Java Programming — I/O Streams
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 41–50 of 100 questions in I/O Streams
Q.41 Easy I/O Streams
What does the flush() method do in output streams?
A Closes the stream
B Clears the buffer and writes data to the underlying stream
C Resets the stream position to the beginning
D Marks the stream for garbage collection
Correct Answer:  B. Clears the buffer and writes data to the underlying stream
EXPLANATION

flush() forces any buffered data to be written to the underlying stream immediately, ensuring data is not lost in the buffer.

Take Test
Q.42 Easy I/O Streams
Which interface must be implemented by a class to make its objects serializable?
A Cloneable
B Serializable
C Comparable
D Iterable
Correct Answer:  B. Serializable
EXPLANATION

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.

Take Test
Q.43 Easy I/O Streams
What is the output of the following code?
FileReader fr = new FileReader("test.txt");
int data = fr.read();
System.out.println(data);
A Character from the file
B ASCII value of the character
C -1 if EOF is reached
D File not found exception
Correct Answer:  B. ASCII value of the character
EXPLANATION

FileReader.read() returns the ASCII/Unicode value of the character as an integer, not the character itself. It returns -1 when EOF is reached.

Take Test
Q.44 Easy I/O Streams
Which class in Java is used to read primitive data types from a binary stream?
A DataInputStream
B BufferedInputStream
C FileInputStream
D ObjectInputStream
Correct Answer:  A. DataInputStream
EXPLANATION

DataInputStream is specifically designed to read primitive data types (int, float, double, etc.) from a binary stream using methods like readInt(), readFloat(), etc.

Take Test
Q.45 Hard I/O Streams
For developing a high-performance file copying utility handling files up to 10GB, which approach is optimal?
A Use FileInputStream/FileOutputStream with 1KB buffer
B Use BufferedInputStream/BufferedOutputStream with large buffer size
C Use FileChannel.transferTo() or NIO channels with direct buffers
D Use ObjectInputStream for binary data
Correct Answer:  C. Use FileChannel.transferTo() or NIO channels with direct buffers
EXPLANATION

FileChannel.transferTo() uses OS-level optimizations for file copying, and NIO channels with direct buffers are most efficient for large file transfers.

Take Test
Advertisement
Q.46 Medium I/O Streams
When combining multiple input sources into one logical stream, which class should be used?
A BufferedInputStream
B PushbackInputStream
C SequenceInputStream
D ConcatInputStream
Correct Answer:  C. SequenceInputStream
EXPLANATION

SequenceInputStream concatenates multiple input streams, reading from them sequentially as if they were a single stream.

Take Test
Q.47 Medium I/O Streams
In a file compression utility, which stream would you use for reading compressed data?
A BufferedInputStream
B GZIPInputStream
C DataInputStream
D FileInputStream
Correct Answer:  B. GZIPInputStream
EXPLANATION

GZIPInputStream decompresses GZIP-compressed data, allowing transparent reading of compressed files as normal streams.

Take Test
Q.48 Medium I/O Streams
What is the primary purpose of transient keyword in Java serialization?
A Make objects read-only
B Exclude specific fields from serialization
C Improve serialization performance
D Synchronize object access
Correct Answer:  B. Exclude specific fields from serialization
EXPLANATION

The transient keyword marks fields that should not be serialized, useful for excluding sensitive data or non-serializable objects.

Take Test
Q.49 Medium I/O Streams
For processing delimited text files with variable field counts, which class is most suitable?
A DataInputStream
B BufferedReader with custom parsing logic
C ObjectInputStream
D RandomAccessFile
Correct Answer:  B. BufferedReader with custom parsing logic
EXPLANATION

BufferedReader combined with custom parsing logic (using split or regex) handles variable-length fields better than fixed-format alternatives.

Take Test
Q.50 Hard I/O Streams
Which serialization approach maintains backward compatibility better?
A Updating serialVersionUID each time the class changes
B Never using serialVersionUID
C Keeping serialVersionUID constant and managing version compatibility in readObject()
D Using random serialVersionUID values
Correct Answer:  C. Keeping serialVersionUID constant and managing version compatibility in readObject()
EXPLANATION

Maintaining a constant serialVersionUID and implementing version-aware readObject() methods allows deserializing objects from different class versions.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips