Entrance Exams
Govt. Exams
Processing large files in chunks using BufferedInputStream with an appropriate buffer size (like 8KB-64KB) balances memory usage and I/O efficiency.
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.
Streams are not thread-safe. Concurrent access by multiple threads can lead to data corruption. Synchronization or separate streams per thread are needed.
DataOutputStream provides methods like writeInt(), writeFloat(), writeDouble() to write primitive types in binary format.
InvalidClassException is thrown when serialVersionUID doesn't match during deserialization, indicating class incompatibility.
BufferedReader.readLine() is the most efficient way to read complete lines as it buffers input and provides a dedicated method for line reading.
mark() records the current position in the stream, and reset() returns to that marked position, useful for lookahead operations.
BufferedInputStream wraps another InputStream and buffers input, reducing the number of actual read operations and improving performance significantly.
flush() forces any buffered data to be written to the underlying stream immediately, ensuring data is not lost in the buffer.
The Serializable interface is a marker interface that indicates a class can be serialized. It's found in java.io package and requires no methods to be implemented.