Java IO Interview Questions & Answers

5 avg. rating (100% score) - 1 votes

Java IO Interview Questions & Answers

Are you prepared in attending an interview? Then do not worry, we’ve a right answer for your job interview preparation. If you are preparing for Java IO job interview and don’t know how to crack interview and what level or difficulty of questions to be asked in job interviews then go through Wisdomjobs Java IO interview questions and answers page to crack your job interview. Java I/O (Input and Output) is used to process the input and produce the output. The java.io package contains all the classes required for input and output operations. Java application uses an input stream to read data from a source. Below is the list of frequently asked Java IO interview questions and answers which gets you ready to face the interviews:

Java IO Interview Questions

Java IO Interview Questions
    1. Question 1. What Is A Io Stream?

      Answer :

      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.

    2. Question 2. What Is The Necessity Of Two Types Of Streams – Byte Streams And Character Streams?

      Answer :

      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.

    3. Question 3. What Are The Super Most Classes Of All Streams?

      Answer :

      All the byte stream classes can be divided into two categories (input stream classes and output stream classes) and all character streams classes into two (reader classes and writer classes). There are four abstract classes from which all these streams are derived. The super most class of all byte stream classes is java.io.InputStream and for all output stream classes, java.io.OutputStream. Similarly for all reader classes is java.io.Reader and for all writer classes is java.io.Writer.

    4. Question 4. What Are Fileinputstream And Fileoutputstream?

      Answer :

      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 Buffered Reader) and BufferedOutputStream (or BufferedWriter).

    5. Question 5. Which You Feel Better To Use – Byte Streams Or Character Streams?

      Answer :

      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 BufferedInputStream 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.

    6. Question 6. What System.out.println()?

      Answer :

      "println()" is a method of PrintStream class. "out" is a static object of PrintStream class defined in "System" class. System is a class from java.lang package used to interact with the underlying operating system by the programmer.

    7. Question 7. What Are Filter Streams?

      Answer :

      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.

    8. Question 8. Name The Filter Streams Available?

      Answer :

      There are four filter streams in java.io package – two in byte streams side and two in character streams side. They are FilterInputStream, FilterOutputStream, FilterReader and FilterWriter. These classes are abstract classes and you cannot create of objects of these classes.

    9. Question 9. Name The Filter Stream Classes On Reading Side Of Byte Stream?

      Answer :

      There are four classes:

      • LineNumberInputStream (the extra functionality is it adds line numbers in the destination file),
      • DataInputStream (contains special methods like readInt(), readDouble() and readLine() etc that can read an int, a double and a string at a time),
      • BufferedInputStream (gives buffering effect that increases the performance to the peak) 
      • PushbackInputStream (pushes the required character back to the system).

    10. Question 10. What Is The Functionality Of Sequence Input Stream?

      Answer :

      It is very useful to copy multiple source files into one destination file with very less code.

    11. Question 11. What Is Print Stream And Print Writer?

      Answer :

      Functionally both are same but belong to two different categories – byte streams and character streams. println() method exists in both classes.

    12. Question 12. Which Streams Are Advised To Use To Have Maximum Performance In File Copying?

      Answer :

      BufferedInputStream and BufferedOutputStream on byte streams side and BufferedReader and BufferedWriter on character streams side.

    13. Question 13. What Are Piped Streams?

      Answer :

      There are four piped streams:

      • PipedInputStream
      • PipedOutputStream
      • PipedReader 
      • PipedWriter

      These streams are very useful to pass data between two running threads (say, processes).

    14. Question 14. What Is File Class?

      Answer :

      It is a non-stream (not used for file operations) class used to know the properties of a file like when it was created (or modified), has read and write permissions, size etc.

    15. Question 15. What Is Randomaccessfile?

      Answer :

      It is a special class from java.io package which is neither a input stream nor a output stream (because it can do both). It is directly a subclass of Object class. Generally, a stream does only one purpose of either reading or writing; but RandomAccessFile can do both reading from a file and writing to a file. All the methods of DataInputStream and DataOutStream exist in RandomAccessFile.


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java Tutorial