Java Streams Interview Questions
26 questions with answers · Java Interview Guide
Stream API operations including map, filter, reduce, collect, and parallel streams.
What features of NIO do you know
NIO features: non-blocking I/O with Selectors, Buffers for efficient data handling, Channels for async operations, multiplexing multiple connections with single thread, memory-mapped file support.
What are "channels"
Channels are abstractions for I/O operations that represent open connections to hardware devices, files, or network sockets; they're part of NIO and support non-blocking I/O unlike traditional streams.
What are the types of input/output streams
Input/output streams are divided into byte streams (InputStream/OutputStream) for raw binary data and character streams (Reader/Writer) for text data.
What are the main classes of input/output streams
Main classes are InputStream, OutputStream, Reader, and Writer; these are abstract base classes from which specific implementations inherit.
In which packages are the classes of input/output streams
I/O classes are in java.io package for traditional streams and java.nio.channels for NIO channels.
What kind of Inputstream class subclasses do you know why they are intended
Key InputStream subclasses: FileInputStream (file reading), ByteArrayInputStream (byte array reading), BufferedInputStream (buffering), DataInputStream (primitive types), ObjectInputStream (object deserialization).
What is PushBackinputstream used for
PushBackInputStream allows you to 'unread' bytes back into the stream, useful for lookahead parsing when you read a byte but need to process it in context.
Why is Sequenceinputstream used
SequenceInputStream concatenates multiple input streams into a single logical stream, allowing sequential reading from multiple sources.
Which class allows you to read data from the input byte stream in the format of primitive data types
DataInputStream wraps another input stream and provides methods to read primitive data types (readInt, readDouble, etc.) in a platform-independent format.
What subclasses of the Outputstream class know what they are for
Key OutputStream subclasses: FileOutputStream (file writing), ByteArrayOutputStream (write to memory), BufferedOutputStream (buffering), DataOutputStream (primitive types), ObjectOutputStream (serialization).
What are the Reader class subclasses what they are for
Reader subclasses: FileReader (file text reading), BufferedReader (buffering with readLine), InputStreamReader (byte-to-char conversion), StringReader (string reading).
What kind of Writer class subclasses do you know why they are intended
Writer subclasses: FileWriter (file text writing), BufferedWriter (buffering), OutputStreamWriter (char-to-byte conversion), PrintWriter (formatted output with print/println).
What is the difference between Printwriter class from Printstream
PrintWriter is character-based with automatic flushing options and better text handling; PrintStream is byte-based and handles System.out/err, though both provide print/println methods.
What is different and what in common has Inputstream, outputstream, Reader, Writer
Common: all are abstract base classes for sequential I/O. Difference: InputStream/OutputStream work with bytes (8-bit), Reader/Writer work with characters (16-bit Unicode), Readers/Writers are wrappers around byte streams.
What classes allow you to convert bytic stream into symbolic and vice versa
InputStreamReader and OutputStreamWriter convert between byte streams and character streams using specified character encodings.
What classes allow you to accelerate reading/recording through the use of the buffer
BufferedInputStream, BufferedOutputStream, BufferedReader, and BufferedWriter use internal buffers to reduce I/O operations and improve performance.
Which class is designed to work with the elements of the file system
File class represents a file or directory path in the file system and provides methods to query/manipulate file metadata without reading file contents.
What are the File class methods
Key File methods: exists(), isFile(), isDirectory(), canRead(), canWrite(), length(), lastModified(), list(), listFiles(), mkdir(), delete(), createNewFile(), renameTo().
What do you know about the FileFilter interface
FileFilter is a functional interface with accept(File f) method used to filter files in File.listFiles(FileFilter); enables selective file listing based on custom criteria.
What do you know about Randomaccessfile
RandomAccessFile allows reading/writing at arbitrary file positions using seek(long pos), supporting both read and write operations with file pointer control; useful for random access patterns.
What kind of access to the file does Randomaccessfile have
RandomAccessFile supports both read and write access to file contents at arbitrary positions using seek() method, allowing non-sequential file operations.
Which classes support reading and recording stream in a compressed format
GZIPInputStream/GZIPOutputStream and ZipInputStream/ZipOutputStream classes support reading and writing compressed stream formats.
Is it possible to redirect the stream of standard input/output
Yes, System.setIn(), System.setOut(), and System.setErr() allow redirection of standard input/output streams programmatically.
What is the symbol by a separator when specifying a path in the file system
The file separator symbol is '/' on Unix/Linux/Mac and '\' on Windows; use File.separator constant for platform independence.
What is the "absolute path" and "relative path"
Absolute path specifies complete location from root directory; relative path specifies location relative to current working directory.
What is a "symbolic link"
A symbolic link is a special file type that acts as a reference/pointer to another file or directory, not containing actual data.
Knowing the answers is half the battle
The other half is explaining them clearly under pressure.
Try a free mock interviewarrow_forward