What will be the output of reading from a ByteArrayInputStream initialized with bytes [65, 66, 67] after calling read() three times?
Answer: A
read() returns integer values of bytes. [65, 66, 67] are ASCII values for 'A', 'B', 'C'. Multiple read() calls return these values sequentially.
Q.522Hard
A developer uses PipedInputStream and PipedOutputStream in the same thread. What will happen?
Answer: B
Pipes require separate threads for reading and writing. Using both in the same thread causes deadlock.
Q.523Medium
Which statement about ObjectOutputStream.reset() is correct?
Answer: B
reset() clears ObjectOutputStream's internal cache of serialized objects, allowing duplicate objects to be serialized again.
Q.524Medium
When implementing Externalizable interface, which method is mandatory?
Answer: C
Externalizable requires implementation of writeExternal() and readExternal() for complete control over serialization.
Q.525Easy
A RandomAccessFile is opened with mode 'r'. Which operation will throw an exception?
Answer: C
Mode 'r' allows read-only access. Write operations will throw IOException.
Advertisement
Q.526Medium
In a CSV file processing application, why is BufferedReader preferred over FileReader for reading large files?
Answer: B
BufferedReader buffers input, reducing system calls and I/O overhead, improving performance significantly.
Q.527Medium
What is the serialVersionUID used for in Java serialization?
Answer: B
serialVersionUID identifies class versions. Mismatched versions cause InvalidClassException during deserialization.
Q.528Hard
A program reads a 1 GB binary file and needs to modify specific bytes at random positions. Which class is most suitable?
Answer: C
RandomAccessFile allows seeking to any position in the file without sequential reading, ideal for random access.
Q.529Medium
What happens when you write to a closed PrintWriter?
Answer: C
PrintWriter suppresses IOException and continues silently, unlike other streams.
Q.530Hard
In Java NIO, what is the primary advantage of FileChannel over traditional streams?
Answer: B
FileChannel enables non-blocking operations and memory-mapping, offering better performance for large files.
Q.531Medium
Which scenario would require using a SequenceInputStream?
Answer: A
SequenceInputStream concatenates multiple input streams, allowing them to be read as one continuous stream.
Q.532Medium
A file contains 1000 lines. Using BufferedReader.readLine() repeatedly reads all lines. What is the time complexity?
Answer: C
Reading each line requires processing each character once, resulting in O(n) complexity where n is total characters.
Q.533Hard
For a real-time log file monitoring application, which approach is most suitable?
Answer: B
RandomAccessFile allows seeking to the file's end to read only new appended data efficiently.
Q.534Easy
Which class in Java I/O streams is used to read primitive data types from a binary file?
Answer: A
DataInputStream provides methods like readInt(), readDouble(), readBoolean() to read primitive data types from a binary file.
Q.535Easy
What is the purpose of the flush() method in PrintWriter?
Answer: B
The flush() method clears the internal buffer and forces any buffered output to be written to the underlying stream without closing it.
Q.536Easy
Which of the following is a character-based stream in Java?
Answer: C
FileReader is a character-based stream that reads characters from a file. InputStream and its subclasses are byte-based streams.
Q.537Medium
In a real-time application processing sensor data streams, which buffering approach would minimize latency?
Answer: B
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.
Q.538Easy
Which class would you use to read and write at arbitrary positions in a file?
Answer: C
RandomAccessFile allows reading and writing at arbitrary positions using seek() method, useful for direct access to file contents.
Q.539Medium
When processing a large XML file, which approach is most memory-efficient?
Answer: C
SAX parsers and streaming XML parsers process XML sequentially without loading the entire document, making them ideal for large files.
Q.540Medium
What is the default charset used by InputStreamReader if none is specified?
Answer: C
If no charset is explicitly provided, InputStreamReader uses the platform's default charset, which varies by system configuration.