|
||
Lesson 4
Objective
|
System.in and System.out
Investigate the System.in and System.out input and output streams. |
|
|
Most sources of data in a Java program are provided as input or output streams.
System.in
System.in and System.out are commonly used to communicate with the user in a character-mode environment and for debugging purposes.
System.in is a static field in the java.lang.System class. It's an input stream
that's normally connected to the console, though some shells
allow the user to redirect it to a file or other program.
In a Unix environment, you normally press Ctrl-D to generate the end-of-stream character on System.in. On most platforms characters are only sent to System.in a line at a time, not as each character is typed. This allows the user to backspace over mistakes and correct them. Java does not allow you to put the console into a "raw" mode that sees each character, including backspaces and deletes, as it is typed.
System.out is also a static field in the java.lang.System class. It's an output
stream that's used to send data from the Java program to the console, though again the shell may allow the user to redirect it to
a file.
AWT
Interestingly, the AWT is not a source of streams in Java.
|
||
|
|
||
