Stream Basics - Quiz Explanation

The correct answers are indicated below, along with text that explains the correct answers.
 
1. Which of the following is not a source of an input stream?
Please select the best answer.
  A. The console
  B. A network socket
  C. A TextArea component
  The correct answer is C.
The TextArea component is not the source of an input stream because the user can type into it and change or modify it at any point. The console is responsible for System.in. Network sockets produce input streams through their getInputStream() methods. Files are the sources for FileInputStreams.


2. What is the fundamental unit in which stream data is read and written?
Please select the best answer.
  A. A bit
  B. A byte
  C. An int
  The correct answer is B.
A bit is the smallest unit of data, but is too small for efficient work. Almost no modern computer systems allow operations on single bits. Instead, Java reads at least one byte at a time. However, since Java automatically promotes bytes to ints whenever they're used in a calculation, all the methods that only read a byte return an int.

3. When you are entering data using the console on a Unix machine, how do you indicate the end-of-stream?
Please select the best answer.
  A. Hold down the Ctrl key and press Z
  B. Hold down the Ctrl key and press D
  C. Hold down the Ctrl key and press C
  The correct answer is B.
Ctrl-Z suspends the current process. Ctrl-D indicates end-of-file or end-of-stream. Ctrl-C terminates the current process. In properly written code, all three will return you to the command-line prompt, but only Ctrl-D will be passed to the running program for interpretation. The other two are handled by the shell.