Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

476 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 201–210 of 476
Topics in Java Programming
Q.201 Medium I/O Streams
What is the purpose of the mark() and reset() methods in buffered streams?
A To bookmark a position and return to it later
B To create a checkpoint in file processing
C To mark end of stream
D To reset the stream encoding
Correct Answer:  A. To bookmark a position and return to it later
EXPLANATION

mark() records the current position in the stream, and reset() returns to that marked position, useful for lookahead operations.

Take Test
Q.202 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.203 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.204 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.205 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.206 Medium I/O Streams
Which method of PushbackInputStream allows you to return bytes to the stream to be read again?
A reset()
B unread()
C rewind()
D goBack()
Correct Answer:  B. unread()
EXPLANATION

The unread() method of PushbackInputStream allows you to push bytes back into the stream so they can be read again.

Take Test
Q.207 Medium I/O Streams
In a multi-threaded application, which stream class is thread-safe?
A FileInputStream
B BufferedReader
C PrintWriter
D FileOutputStream
Correct Answer:  C. PrintWriter
EXPLANATION

PrintWriter is synchronized, making it thread-safe. Other stream classes are not inherently thread-safe and require external synchronization in multi-threaded contexts.

Take Test
Q.208 Medium I/O Streams
What is the default charset used by InputStreamReader if none is specified?
A UTF-8
B ISO-8859-1
C System default charset
D ASCII
Correct Answer:  C. System default charset
EXPLANATION

If no charset is explicitly provided, InputStreamReader uses the platform's default charset, which varies by system configuration.

Take Test
Q.209 Medium I/O Streams
When processing a large XML file, which approach is most memory-efficient?
A Load entire file into memory using FileInputStream
B Use BufferedReader to read line-by-line
C Use SAX parser or streaming XML parser
D Convert file to ObjectInputStream
Correct Answer:  C. Use SAX parser or streaming XML parser
EXPLANATION

SAX parsers and streaming XML parsers process XML sequentially without loading the entire document, making them ideal for large files.

Take Test
Q.210 Medium I/O Streams
In a real-time application processing sensor data streams, which buffering approach would minimize latency?
A Increase buffer size to 64KB
B Use unbuffered I/O or very small buffer sizes with frequent flush()
C Use ObjectInputStream for all data
D Implement custom byte arrays
Correct Answer:  B. Use unbuffered I/O or very small buffer sizes with frequent flush()
EXPLANATION

For real-time applications requiring minimal latency, smaller buffer sizes and frequent flushing ensure data is processed immediately rather than waiting for buffer to fill.

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