Printing Text with System.out.println

Getting Java to talk back to you

6 min read

In the last lesson you saw this line of code: System.out.println("Hello, world!");. Now let's break down exactly what it does.

System.out represents the standard output of your program, which in most cases is the console or terminal window where you see your program's results.

println is short for print line. It takes whatever you give it, in this case the text Hello, world!, and displays it on the screen, then moves to a new line afterward so the next thing you print starts fresh.

Printing different kinds of things

You can print plain text, called a string, by wrapping it in double quotes:

System.out.println("I am learning Java!");

You can also print numbers directly, without any quotes:

System.out.println(42);
System.out.println(3.14);

There is also a close relative called print, without the ln. It prints the text but does not move to a new line afterward, so the next thing you print appears right next to it.

System.out.print("Hello, ");
System.out.println("world!");

Running those two lines together produces a single line of output: Hello, world!

Try it yourself: Change the text inside the quotes to your own name and imagine running the program. What would appear on the screen?

Printing is one of the simplest things you can do in Java, but you will use it constantly, especially while you are learning, to check what your program is doing at each step.

Quick check

Q1 What does System.out.println do?

Q2 How is print different from println?

Want to save your progress? It's free.

Create a free account