What is the default buffer size of BufferedReader in Java?
Answer: C
BufferedReader has a default buffer size of 8192 characters, but commonly 2048 bytes is used. The exact implementation may vary, but 8192 is the default character buffer.
Q.2Medium
What happens when you try to read from a closed stream in Java?
Answer: B
Attempting to read from a closed stream throws an IOException. The stream must be open for read operations.
Q.3Medium
Which of the following is a filtered stream?
Answer: B
BufferedOutputStream is a filtered stream that adds buffering capability to an underlying output stream. Filtered streams wrap other streams to add functionality.
Q.4Medium
Which class is used to read primitive data types from a stream?
Answer: B
DataInputStream provides methods like readInt(), readDouble(), readBoolean() to read primitive data types from a stream.
Q.5Medium
Which of the following creates a bridge between character and byte streams?
Answer: B
InputStreamReader converts a byte stream (InputStream) into a character stream (Reader), acting as a bridge between the two.
Advertisement
Q.6Medium
What is the difference between FileInputStream and BufferedInputStream?
Answer: B
FileInputStream reads directly from a file byte by byte, while BufferedInputStream wraps another stream and adds buffering to improve performance by reducing I/O operations.
Q.7Medium
Which class allows reading and writing objects to a stream?
Answer: B
ObjectInputStream and ObjectOutputStream are used for serialization and deserialization of Java objects. Objects must implement Serializable interface.
Q.8Medium
What is the mark() method used for in BufferedReader?
Answer: B
The mark() method marks the current position in the stream so it can be returned to later using reset(). Requires markSupported() to return true.
Q.9Medium
Which of the following statements will correctly read a file line by line?
Answer: B
BufferedReader's readLine() method is the standard way to read lines. FileInputStream doesn't have readLine(), FileReader doesn't have readLine() either.
Q.10Medium
What is the purpose of the skip() method in InputStream?
Answer: B
The skip(long n) method skips n bytes in the input stream and returns the number of bytes actually skipped.
Q.11Medium
A Java program needs to read a file containing 10 million integers. Which approach would be most memory-efficient?
Answer: C
DataInputStream with buffering allows sequential reading without loading the entire file into memory, making it ideal for large files.
Q.12Medium
A serialized object contains a field marked as 'transient'. What happens to this field when the object is deserialized?
Answer: B
Transient fields are excluded from serialization and are initialized to default values upon deserialization.
Q.13Medium
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.14Medium
When implementing Externalizable interface, which method is mandatory?
Answer: C
Externalizable requires implementation of writeExternal() and readExternal() for complete control over serialization.
Q.15Medium
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.16Medium
What is the serialVersionUID used for in Java serialization?
Answer: B
serialVersionUID identifies class versions. Mismatched versions cause InvalidClassException during deserialization.
Q.17Medium
What happens when you write to a closed PrintWriter?
Answer: C
PrintWriter suppresses IOException and continues silently, unlike other streams.
Q.18Medium
Which scenario would require using a SequenceInputStream?
Answer: A
SequenceInputStream concatenates multiple input streams, allowing them to be read as one continuous stream.
Q.19Medium
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.20Medium
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.