Home Subjects Java Programming I/O Streams

Java Programming
I/O Streams

Java OOP, collections, multithreading

53 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 53
Topics in Java Programming
Q.31 Medium I/O Streams
What is the default charset used by InputStreamReader if none is specified?
A UTF-8
B ISO-8859-1
C System default charset
D ASCII
Correct Answer:  C. System default charset
EXPLANATION

If no charset is explicitly provided, InputStreamReader uses the platform's default charset, which varies by system configuration.

Test
Q.32 Medium I/O Streams
When processing a large XML file, which approach is most memory-efficient?
A Load entire file into memory using FileInputStream
B Use BufferedReader to read line-by-line
C Use SAX parser or streaming XML parser
D Convert file to ObjectInputStream
Correct Answer:  C. Use SAX parser or streaming XML parser
EXPLANATION

SAX parsers and streaming XML parsers process XML sequentially without loading the entire document, making them ideal for large files.

Test
Q.33 Medium I/O Streams
In a real-time application processing sensor data streams, which buffering approach would minimize latency?
A Increase buffer size to 64KB
B Use unbuffered I/O or very small buffer sizes with frequent flush()
C Use ObjectInputStream for all data
D Implement custom byte arrays
Correct Answer:  B. Use unbuffered I/O or very small buffer sizes with frequent flush()
EXPLANATION

For real-time applications requiring minimal latency, smaller buffer sizes and frequent flushing ensure data is processed immediately rather than waiting for buffer to fill.

Test
Q.34 Medium I/O Streams
What exception is thrown when trying to deserialize an object that was serialized with a different serialVersionUID?
A ClassCastException
B InvalidClassException
C StreamCorruptedException
D NotSerializableException
Correct Answer:  B. InvalidClassException
EXPLANATION

InvalidClassException is thrown when a serialized object's serialVersionUID doesn't match the current class definition, indicating an incompatible class version.

Test
Q.35 Medium I/O Streams
A file contains 1000 lines. Using BufferedReader.readLine() repeatedly reads all lines. What is the time complexity?
A O(1)
B O(log n)
C O(n)
D O(n²)
Correct Answer:  C. O(n)
EXPLANATION

Reading each line requires processing each character once, resulting in O(n) complexity where n is total characters.

Test
Q.36 Medium I/O Streams
Which scenario would require using a SequenceInputStream?
A Reading from multiple files sequentially as a single stream
B Reading very large files
C Parallel reading from multiple files
D Converting stream encoding
Correct Answer:  A. Reading from multiple files sequentially as a single stream
EXPLANATION

SequenceInputStream concatenates multiple input streams, allowing them to be read as one continuous stream.

Test
Q.37 Medium I/O Streams
What happens when you write to a closed PrintWriter?
A The data is buffered and written on next open
B IOException is thrown
C Data is silently discarded
D The stream reopens automatically
Correct Answer:  C. Data is silently discarded
EXPLANATION

PrintWriter suppresses IOException and continues silently, unlike other streams.

Test
Q.38 Medium I/O Streams
What is the serialVersionUID used for in Java serialization?
A To store the Java version number
B To identify the class version for deserialization compatibility
C To encrypt the serialized object
D To track the number of times an object was serialized
Correct Answer:  B. To identify the class version for deserialization compatibility
EXPLANATION

serialVersionUID identifies class versions. Mismatched versions cause InvalidClassException during deserialization.

Test
Q.39 Medium I/O Streams
In a CSV file processing application, why is BufferedReader preferred over FileReader for reading large files?
A BufferedReader automatically parses CSV format
B BufferedReader reduces I/O operations by reading data in chunks
C FileReader cannot read text files
D BufferedReader is faster at character encoding
Correct Answer:  B. BufferedReader reduces I/O operations by reading data in chunks
EXPLANATION

BufferedReader buffers input, reducing system calls and I/O overhead, improving performance significantly.

Test
Q.40 Medium I/O Streams
When implementing Externalizable interface, which method is mandatory?
A serialize()
B writeObject() and readObject()
C writeExternal() and readExternal()
D write() and read()
Correct Answer:  C. writeExternal() and readExternal()
EXPLANATION

Externalizable requires implementation of writeExternal() and readExternal() for complete control over serialization.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips