What is the serialVersionUID used for in Java serialization?
Answer: B
serialVersionUID identifies class versions. Mismatched versions cause InvalidClassException during deserialization.
Q.262Medium
What happens when you write to a closed PrintWriter?
Answer: C
PrintWriter suppresses IOException and continues silently, unlike other streams.
Q.263Medium
Which scenario would require using a SequenceInputStream?
Answer: A
SequenceInputStream concatenates multiple input streams, allowing them to be read as one continuous stream.
Q.264Medium
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.265Medium
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.
Advertisement
Q.266Medium
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.267Medium
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.
Q.268Medium
In a multi-threaded application, which stream class is thread-safe?
Answer: C
PrintWriter is synchronized, making it thread-safe. Other stream classes are not inherently thread-safe and require external synchronization in multi-threaded contexts.
Q.269Medium
Which method of PushbackInputStream allows you to return bytes to the stream to be read again?
Answer: B
The unread() method of PushbackInputStream allows you to push bytes back into the stream so they can be read again.
Q.270Medium
For processing delimited text files with variable field counts, which class is most suitable?
Answer: B
BufferedReader combined with custom parsing logic (using split or regex) handles variable-length fields better than fixed-format alternatives.
Q.271Medium
What is the primary purpose of transient keyword in Java serialization?
Answer: B
The transient keyword marks fields that should not be serialized, useful for excluding sensitive data or non-serializable objects.
Q.272Medium
In a file compression utility, which stream would you use for reading compressed data?
Answer: B
GZIPInputStream decompresses GZIP-compressed data, allowing transparent reading of compressed files as normal streams.
Q.273Medium
When combining multiple input sources into one logical stream, which class should be used?
Answer: C
SequenceInputStream concatenates multiple input streams, reading from them sequentially as if they were a single stream.
Q.274Medium
What is the purpose of the mark() and reset() methods in buffered streams?
Answer: A
mark() records the current position in the stream, and reset() returns to that marked position, useful for lookahead operations.
Q.275Medium
Consider a scenario where you need to read a line from a file. Which class would be most efficient?
Answer: B
BufferedReader.readLine() is the most efficient way to read complete lines as it buffers input and provides a dedicated method for line reading.
Q.276Medium
In a multi-threaded application, what is a concern when sharing streams between threads?
Answer: B
Streams are not thread-safe. Concurrent access by multiple threads can lead to data corruption. Synchronization or separate streams per thread are needed.
Q.277Medium
What is the difference between InputStreamReader and FileReader?
Answer: D
InputStreamReader is a bridge from byte streams to character streams and accepts any InputStream with optional charset. FileReader is specifically for file input with default charset.
Q.278Medium
Consider processing a 1GB file. Which approach would be most memory-efficient?
Answer: C
Processing large files in chunks using BufferedInputStream with an appropriate buffer size (like 8KB-64KB) balances memory usage and I/O efficiency.
Q.279Medium
What does the available() method in InputStream return?
Answer: A
available() returns an estimate of bytes that can be read without blocking. It doesn't return total file size.
Q.280Medium
In Java NIO, which class is used for channel-based I/O?
Answer: B
FileChannel provides non-blocking and efficient I/O operations, memory-mapped file access, and file locking capabilities compared to traditional streams.