CH3 – The System Class

  1. Create a new class named SystemExample.
  1. Type the following code.
public class SystemExample {
  public static void main(String[] args){
    System.out.println(System.out);
  }
}
  1. Compile the program and run.
$ javac SystemExample.java
$ java SystemExample
java.io.PrintStream@6d06d69c

The output prints not the object’s value, but rather the class name followed by it’s value as provided by System.identityHashCode. This is the object’s address in memory.  As the program runs, think of the variables instantiated as being stored in “cubby-holes” the location in memory is the individual “cubby-hole’s nameplate” not the actual content.

The System class provides access to the computer operating system running the program. System.out is standard output, System.in is standard input, and System.err is standard error.

In the book and in these tutorials, the System class you refer to most is System.out, which you use of printing results to the command-line.

The System class also provides numerous utility methods such as getting your operating system’s environment variables, obtaining your system’s time, and other tasks. Refer to Oracle’s documentation on the System class for more information.