System.out in Java explained

The first line of code that new developers encounter when they write their first Java program typically includes a call to System.out.println().

If you’ve ever written a Java program, the following line of code will look familiar to you:

System.out.println("Hello World!");

But what exactly does System.out.println mean, and how can we explain it in plain English?

Meaning of System.out.println() in Java

As is often the case in Java, the best way to explain System.out.println(“Hello World”) is to read it from right to left. Take the provided text (“Hello World”) and display it (print) in the output window (out) associated with the program (System) running this Java code.

Note that when we say print in this case, we’re not talking about sending text to a dot-matrix or a laser-jet printer. In this case, print just means ‘display it on your computer screen.’

The four key components associated with this line of code are as follows:

  1. The System class that provides standard mechanisms to obtain input, write output and log error messages.
  2. The PrintStream named out which can be configured to write text to either the console window or to log files.
  3. The print method which is passed a text String to print out.
  4. The text String provided as an argument to the print method.

System’s overloaded println method

The System.out.println() method is incredibly versatile because it is overloaded to support a variety of objects and data types. As a result, it has the ability to print details about the following values:

  • String
  • boolean
  • float
  • char
  • int
  • long
  • byte
  • short
  • double

Furthermore, the println method invokes the toString() method of any objects passed as an argument, so it has the ability to display details of instances of Java classes.

It can even be left blank just to force the generation of a newline.

What System.out.println means

The System class is one of the foundation classes in Java.

System out println examples

Here are some examples of how to use the System.out.println() method call to display the values of various Java data types and values:

int y = 20; 
System.out.println();    // prints a new line
System.out.println(y);   // prints 10
System.out.println(10);  // prints 10 
System.out.println('x'); // prints x
System.out.println(10.10);   // prints 10.10
System.out.println(10!=10);  // prints false
System.out.println(Math.PI); // prints 3.14...
System.out.println("Hello World!); // prints Hello World

Tips and tricks with System.out.println()

New developers often get tripped up on the syntax of the System.out.println() method call. Here are a few things to remember:

  • Java is case sensitive, so System must start with an uppercase S. Writing system.out.println() will result in a compilation error.
  • Every line of code in Java must end with a semi-colon. If you forget it, your code won’t compile.
  • Any multi-character text passed as an argument to the println method must be in double quotes, like “Hello, world!”. Using single quotes for a string will cause an error.
  • Single quotes are only used for single characters, such as ‘A’ or ‘9’. These are considered char values in Java, not strings.

Have fun working with the System object and printing data to the console or terminal window as you learn how to program in Java. It makes it easier to get feedback and make sure your program is working properly.