Entrance Exams
Govt. Exams
BufferedReader with readLine() processes the file line-by-line, maintaining a constant memory footprint regardless of file size. Options A, C, and D would attempt to load the entire 5GB file into memory, causing OutOfMemoryError. This is the standard approach for large file processing.
Java serialization requires all instance variables to be serializable or marked as transient. If a non-serializable object is encountered during serialization, NotSerializableException is thrown at runtime, not compile-time. There's no automatic conversion.
ObjectOutputStream and ObjectInputStream are specifically designed for object serialization and deserialization. They handle the complete object state preservation. Other options are either inefficient or unsuitable for preserving object state.
DataInputStream is specifically designed to read primitive data types like int, double, boolean, etc. from an input stream. BufferedInputStream provides buffering, FileInputStream reads from files, and ObjectInputStream deserializes objects.
PushbackInputStream allows you to 'unread' bytes using the unread() method. This is useful for parsers that need to look ahead without consuming the data.
BufferedInputStream provides automatic buffering (8KB default), and DataInputStream allows reading typed data. Together they enable efficient reading of large binary files without loading everything into memory.
During deserialization, the constructor is NOT called. readObject() restores the object state directly from the serialized data. This is why transient fields need special handling.
RandomAccessFile allows you to read/write at any position in a file using seek() method. Sequential streams can only read/write sequentially from current position.
Try-with-resources automatically closes resources in reverse order (LIFO). All resources must implement AutoCloseable. This ensures proper resource cleanup even if exceptions occur.
InputStreamReader is a bridge between byte streams and character streams. It converts bytes to characters using specified character encoding (UTF-8, ISO-8859-1, etc.).