While it is a bit of an over-simplification, you can think of the System class as representing the computer system on which your java program is running.
The System class is part of the Java language itself and no import directive is needed to use this class.
The System class has three components (called fields in java):
PrintStream out - the standard output stream (to the terminal window) InputStream in - the standard input stream (from the keyboard)
These components provide basic input and output capabilities to a Java application. The standard output stream allows a user to display text on the computer screen. Since "out" is a PrintStream object, it can invoke the PrintStream methods "print" and "println" to send text to the standard output device:
The argument, data, represents the data you want to display and can be of any primitive data type. The difference between "print" and "println" is that "print" will leave the cursor position at the end of the current line while "println" will advance the cursor position to the beginning of the next line.
The standard input stream allows the user to input text from the keyboard. In most applications, "in" is used to create a Scanner object which, in turn, takes the text entered by the user and converts it to an appropriate primitive data value. The Java statement below, creates a Scanner named "kb" (short for keyboard) that scans the text coming from the standard input stream.
Scanner kb = new Scanner(System.in);
The exit method terminates a java application. In our programs, we will use an exit code of zero. The following statement will cause a Java program to terminate:
See also: Scanner