Java Programming — I/O Streams
Java OOP, collections, multithreading
27 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 27 questions in I/O Streams
Q.1 Easy I/O Streams
Which interface must a class implement to be eligible for serialization in Java, and what is the significance of implementing it with no abstract methods?
A Cloneable interface; it marks the class as eligible for deep copying
B Serializable interface; it's a marker interface with no abstract methods that indicates serialization capability
C Externalizable interface; it provides default serialization behavior
D Comparable interface; it enables object comparison during serialization
Correct Answer:  B. Serializable interface; it's a marker interface with no abstract methods that indicates serialization capability
EXPLANATION

Serializable is a marker interface (contains no methods) that signals to the JVM that objects of that class can be serialized. The absence of abstract methods means implementing classes don't need to override any methods; they just need to implement the interface to indicate serialization support.

Take Test
Q.2 Easy I/O Streams
Which of the following classes is used to read primitive data types from an input stream in Java?
A DataInputStream
B BufferedInputStream
C FileInputStream
D ObjectInputStream
Correct Answer:  A. DataInputStream
EXPLANATION

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.

Take Test
Q.3 Easy I/O Streams
What will be the output of the following code?
FileOutputStream fos = new FileOutputStream("test.txt", true);
What does the 'true' parameter indicate?
A The file should be read-only
B The file should be overwritten
C The data should be appended to the existing file
D The file should be encrypted
Correct Answer:  C. The data should be appended to the existing file
EXPLANATION

The second parameter 'true' in FileOutputStream constructor indicates append mode. If 'false' or omitted, the file is overwritten. With 'true', new data is appended to the existing file.

Take Test
Q.4 Easy I/O Streams
In Java, what is the primary purpose of the flush() method in output streams?
A To close the stream permanently
B To clear the internal buffer and write pending data
C To reset the stream position to the beginning
D To increase the buffer size
Correct Answer:  B. To clear the internal buffer and write pending data
EXPLANATION

The flush() method forces any buffered output bytes to be written out. It does not close the stream, allowing further writes after flushing.

Take Test
Q.5 Easy I/O Streams
Which interface must be implemented to make an object serializable in Java?
A Cloneable
B Serializable
C Comparable
D Iterable
Correct Answer:  B. Serializable
EXPLANATION

The Serializable interface must be implemented to serialize objects. It is a marker interface with no methods. Classes implementing it can be serialized using ObjectOutputStream.

Take Test
Advertisement
Q.6 Easy I/O Streams
Which of the following is NOT a character stream class in Java?
A FileReader
B BufferedWriter
C FileInputStream
D PrintWriter
Correct Answer:  C. FileInputStream
EXPLANATION

FileInputStream is a byte stream class, not a character stream. FileReader, BufferedWriter, and PrintWriter are all character stream classes.

Take Test
Q.7 Easy I/O Streams
Which stream class is used to write primitive data types in binary format?
A PrintWriter
B DataOutputStream
C BufferedOutputStream
D ObjectOutputStream
Correct Answer:  B. DataOutputStream
EXPLANATION

DataOutputStream provides methods like writeInt(), writeFloat(), writeDouble() to write primitive types in binary format.

Take Test
Q.8 Easy I/O Streams
Which class provides buffering capability to improve I/O performance?
A FileInputStream
B BufferedInputStream
C ByteArrayInputStream
D PipedInputStream
Correct Answer:  B. BufferedInputStream
EXPLANATION

BufferedInputStream wraps another InputStream and buffers input, reducing the number of actual read operations and improving performance significantly.

Take Test
Q.9 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.10 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
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