Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

476 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 221–230 of 476
Topics in Java Programming
Q.221 Medium I/O Streams
What is the purpose of the skip() method in InputStream?
A Skip the entire stream
B Skip a specified number of bytes in the stream
C Skip to the end of the stream
D Skip error handling
Correct Answer:  B. Skip a specified number of bytes in the stream
EXPLANATION

The skip(long n) method skips n bytes in the input stream and returns the number of bytes actually skipped.

Take Test
Q.222 Medium I/O Streams
Which of the following statements will correctly read a file line by line?
A FileInputStream fis = new FileInputStream("file.txt"); String line = fis.readLine();
B BufferedReader br = new BufferedReader(new FileReader("file.txt")); String line = br.readLine();
C FileReader fr = new FileReader("file.txt"); String line = fr.readLine();
D DataInputStream dis = new DataInputStream(new FileInputStream("file.txt")); String line = dis.readLine();
Correct Answer:  B. BufferedReader br = new BufferedReader(new FileReader("file.txt")); String line = br.readLine();
EXPLANATION

BufferedReader's readLine() method is the standard way to read lines. FileInputStream doesn't have readLine(), FileReader doesn't have readLine() either.

Take Test
Q.223 Medium I/O Streams
What is the mark() method used for in BufferedReader?
A Mark end of stream
B Mark current position in stream for later reset
C Mark data as corrupted
D Mark stream as closed
Correct Answer:  B. Mark current position in stream for later reset
EXPLANATION

The mark() method marks the current position in the stream so it can be returned to later using reset(). Requires markSupported() to return true.

Take Test
Q.224 Medium I/O Streams
Which class allows reading and writing objects to a stream?
A DataInputStream and DataOutputStream
B ObjectInputStream and ObjectOutputStream
C SerializableInputStream
D ByteArrayStream
Correct Answer:  B. ObjectInputStream and ObjectOutputStream
EXPLANATION

ObjectInputStream and ObjectOutputStream are used for serialization and deserialization of Java objects. Objects must implement Serializable interface.

Take Test
Q.225 Medium I/O Streams
What is the difference between FileInputStream and BufferedInputStream?
A No difference; they are aliases
B FileInputStream reads directly from file; BufferedInputStream adds buffering for efficiency
C BufferedInputStream reads characters; FileInputStream reads bytes
D FileInputStream is deprecated in Java 11+
Correct Answer:  B. FileInputStream reads directly from file; BufferedInputStream adds buffering for efficiency
EXPLANATION

FileInputStream reads directly from a file byte by byte, while BufferedInputStream wraps another stream and adds buffering to improve performance by reducing I/O operations.

Take Test
Q.226 Medium I/O Streams
Which of the following creates a bridge between character and byte streams?
A BufferedReader
B InputStreamReader
C DataInputStream
D ObjectInputStream
Correct Answer:  B. InputStreamReader
EXPLANATION

InputStreamReader converts a byte stream (InputStream) into a character stream (Reader), acting as a bridge between the two.

Take Test
Q.227 Medium I/O Streams
Which class is used to read primitive data types from a stream?
A ObjectInputStream
B DataInputStream
C BufferedInputStream
D InputStreamReader
Correct Answer:  B. DataInputStream
EXPLANATION

DataInputStream provides methods like readInt(), readDouble(), readBoolean() to read primitive data types from a stream.

Take Test
Q.228 Medium I/O Streams
Which of the following is a filtered stream?
A FileOutputStream
B BufferedOutputStream
C ByteArrayOutputStream
D PipedOutputStream
Correct Answer:  B. BufferedOutputStream
EXPLANATION

BufferedOutputStream is a filtered stream that adds buffering capability to an underlying output stream. Filtered streams wrap other streams to add functionality.

Take Test
Q.229 Medium I/O Streams
What happens when you try to read from a closed stream in Java?
A Returns -1
B Throws IOException
C Returns null
D Blocks indefinitely
Correct Answer:  B. Throws IOException
EXPLANATION

Attempting to read from a closed stream throws an IOException. The stream must be open for read operations.

Take Test
Q.230 Medium I/O Streams
What is the default buffer size of BufferedReader in Java?
A 512 bytes
B 1024 bytes
C 2048 bytes
D 4096 bytes
Correct Answer:  C. 2048 bytes
EXPLANATION

BufferedReader has a default buffer size of 8192 characters, but commonly 2048 bytes is used. The exact implementation may vary, but 8192 is the default character buffer.

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