Study guide: The ins and outs of standard input/output

Brush up on Java terms, learn tips and cautions, review homework assignments, and read Jeff's answers to student questions

Glossary of terms

standard error device
That part of the operating system that controls where a program sends error messages.
standard I/O
A standardized input/output mechanism that originates from the Unix operating system. It uses devices for inputting and outputting data.
standard input device
That part of the operating system that controls from where a program receives its input.
standard output device
That part of the operating system that controls where a program sends its output.

Tips and cautions

These tips and cautions will help you write better programs and save you from agonizing over why the compiler produces error messages.

Tips

  • When using java.exe to run an application, you can redirect standard output, so that output arrives at a file instead of the screen. You accomplish that task by specifying the greater-than-sign (>) character followed by a filename after java.exe on a command line.
  • When using java.exe to run an application, you can redirect standard input, so that input originates from a file instead of the keyboard. You accomplish that task by specifying the less-than-sign (<) character followed by a filename after java.exe on a command line.
  • Use System.err instead of System.out for outputting error messages. After all, a user might become confused if a problem occurs in a program and no error message appears on the screen because the message is sent to the standard output device -- which has been redirected from the screen to a file.

Cautions

  • System.in.read() does not return user-entered integer numbers. Instead, it returns either a key's 7-bit ASCII code or a file's 8-bit byte.
  • System.in.read() can throw exceptions.

Homework

Because the last several articles have covered a lot of detailed material, this shorter article provides a brief respite. As an added bonus, there is no homework.

Answers to last month's homework

Last month, I presented the first of several Java 101 quizzes. Each quiz is designed to get you thinking about concepts introduced in the Java 101 course and to help prepare you for certification. This month, those questions are answered. Check out the following answers to see how well you're doing!

Related:
1 2 Page 1
Page 1 of 2