Java Input Output - Quiz Explanation

The correct answers are indicated below, along with text that explains the correct answers.
1. If you wanted to support internationalization in your Java program, which one of the following I/O classes would you need to use?
Please select the best answer.
  A. InputStream
  B. FileReader
  C. FileInputStream
  The correct answer is B. If you wanted to support internationalization in your Java program, you would need to use the FileReader class. InputStream and FileInputStream don't support the Unicode character set, and therefore aren't suitable for internationalized programs.


2. Which one of the following stream classes is a data source?
Please select the best answer.
  A. FilterReader
  B. BufferedReader
  C. StringReader
  The correct answer is C. The StringReader class is a data source because it is implicitly associated with a source of data, a string. The FilterReader and BufferedReader classes are intermediate stream classes and do not have data sources directly associated with them--they must always be used with other stream classes that are data sources.

3. What type of object is the standard System.in object?
Please select the best answer.
  A. InputStream
  B. Reader
  C. BufferedInputStream
  The correct answer is A. The standard System.in object is an InputStream object. Although the Reader and BufferedInputStream objects might work for the System.in object, the InputStream object is the one used.


4. In the BufferedReader class, what does the readLine() method return when it reaches the end of the stream?
Please select the best answer.
  A. 0
  B. -1
  C. null
  The correct answer is C. In the BufferedReader class, the readLine() method returns null when it reaches the end of the stream. I/O methods never return 0 to indicate the end of a stream being reached. The read() method is the I/O method that returns -1 when the end of the stream is reached, not readLine(). read() returns an integer data type and readLine() returns a String object type.