25C. Java Basics for Selenium - File Operations - File Input and Output Interview Questions

preview_player
Показать описание
In this video we will see some interview questions on File Input and Output operations.
What is a stream and what are the types of Streams and classes of the Streams?
A stream is a sequence of data. In Java, a stream is composed of bytes. It's called a stream because it is like a stream of water that continues to flow. There are two types of Streams :
Byte Streams: Provide a convenient means for handling input and output of bytes.
Character Streams: Provide a convenient means for handling input & output of characters.
Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream.
Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.
What is an IO stream?
It is a stream of data that flows from source to destination. Good example is file copying. Two streams are involved – input stream and output stream. An input stream reads from the file and stores the data in the process (generally in a temporary variable). The output stream reads from the process and writes to the destination file.
What is the necessity of two types of streams – byte streams and character streams?
Byte streams were introduced with JDK 1.0 and operate on the files containing ASCII characters. We know Java supports other language characters also known as Unicode characters. To read the files containing Unicode characters, the designers introduced character streams with JDK 1.1. As ASCII is a subset of Unicode, for the files of English characters, we can go with either byte streams or character streams.
What are the super most classes of all streams?
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented
What value does read() return when it has reached the end of a file?
The read() method returns -1 when it has reached the end of a file.
What is the package name for ObjectInputStream class?
Which is the Parent Class of StringBufferInputStream class?
InputStream
Note: Anything that ends with InputStream are subclasses of InputStream.
Anything that ends with OutputStream are subclasses of OutputStream.
Anything that ends with Reader are subclasses of Reader.
Anything that ends with Writer are subclasses of Writer.
What are FileInputStream and FileOutputStream?
These two are general purpose classes used by the programmer very often to copy file to file. These classes work well with files containing less data of a few thousand bytes as by performance these are very poor. For larger data, it is preferred to use BufferedInputStream (or BufferedReader) and BufferedOutputStream (or BufferedWriter).
Which you feel better to use – byte streams or character streams?
I feel personally to go with character streams as they are the latest. Many features exist in character streams that do not in byte streams like a) using BufferedReader in place of BufferedInputStreams and DataInputStream (one stream for two) and b) using newLine() method to go for next line and for this effect we must go for extra coding in byte streams etc.
What are filter streams?
Filter streams are a category of IO streams whose responsibility is to add extra functionality (advantage) to the existing streams like giving line numbers in the destination file that do not exist int the source file or increasing performance of copying etc.
Name the filter streams available?
Рекомендации по теме