Java IO Streams - Quiz Explanation

The correct answers are indicated below, along with text that explains the correct answers.
1. What standard Java package provides support for I/O?
Please select the best answer.
  A. java.io
  B. java.inputoutput
  C. java.stream
  The correct answer is A. The java.io package provides support for I/O. There are no such standard Java packages as java.inputoutput and java.stream.


2. In Java I/O, a medium through which data is transferred is known as:
Please select the best answer.
  A. A socket
  B. A stream
  C. A pipeline
  The correct answer is B. In Java I/O, a medium through which data is transferred is known as a stream. A socket is a medium through which data is transferred over a network. And although a stream is analogous to a pipe in the real world, the term pipeline does not directly apply to Java I/O.

3. Which one of the following classes would you use to read data as a primitive Java data type?
Please select the best answer.
  A. InputStream
  B. DataInputStream
  C. Reader
  The correct answer is B. The DataInputStream class is used to read data as a primitive Java data type. InputStream and Reader both read data in terms of bytes or characters.

4. What method in the OutputStream class is used to force the contents of an output buffer to be written to an output device?
Please select the best answer.
  A. reset()
  B. write()
  C. flush()
  The correct answer is C. The flush() method in the OutputStream class is used to force the contents of an output buffer to be written to an output device. The reset() method is only defined in the InputStream class, not the OutputStream class. The write() method will only write data to the output buffer, and will not force it to be written to an output device. An output buffer is only written automatically if the buffer gets full.