CodeGym /Courses /JAVA 25 SELF /Console output in Java: System.out.println and System.out...

Console output in Java: System.out.println and System.out.print

JAVA 25 SELF
Level 1, Lesson 2
Available

1. Getting to know the System.out.println command

You have just written your first program in Java and printed the first message to the screen. Congratulations on that. Let’s not stop now…

Any Java program consists of commands. Commands come in different kinds. The Java language has commands for every occasion. Each command describes a specific action. At the end of each command, a semicolon is placed.

Examples of commands:

Command Description (what it does)
System.out.println(2025);
Prints the number to the screen:
2025
System.out.println("Ciao 🍕");
Prints the text:
Ciao 🍕
System.out.println("こんにちは 🗾");
Prints the text:
こんにちは 🗾

In fact, this is a single command — System.out.println. And in parentheses you pass parameters to it. Depending on the parameter values, one command can perform different actions. That’s very convenient.

Case matters

In Java, case matters: it’s important whether commands are written with uppercase or lowercase letters. The command System.out.println() will work, but system.out.println() will not. If you write a command with the wrong case, Java won’t recognize it and therefore won’t execute it. So be careful.

Double quotes

If you want to print text to the screen, you need to enclose it in double quotes.

A single quote looks like this ', and a double quote looks like this ". A double quote is not two single quotes—please don’t confuse them.

The double quote is the one next to the Enter key. It often also has the Cyrillic letter "E" on it.

2. Getting to know the System.out.print command

There is another command similar to System.out.println(), and it is called System.out.print().

The System.out.println() command prints text to the screen and then adds a line break, as if pressing Enter. This way, the next System.out.println() command will print text on the next line. And the next command—on the next line, and so on.

Unlike System.out.println(), the System.out.print() command does not add Enter after printing text. Therefore, text printed by several System.out.print() commands will be printed on a single line.

Example 1:
System.out.print("Amigo"); 
System.out.println("The"); 
System.out.print("Best");
Mixed output with print and println

This will print:

AmigoThe
Best
Example 2:
System.out.print("Amigo"); 
System.out.print("The"); 
System.out.print("Best");
Only print—everything on one line

This will print:

AmigoTheBest

If you want to print text on one line, use print(); if on multiple lines—use println(). It’s that simple.

3. Breaking down the System.out.println command

If you know at least a little English, learning programming will be much easier. The names of many commands in Java are directly related to what they do.

For example, println is print + line — print line. The word print is familiar to everyone, and why specifically “line,” I’ll explain now. Each line of text on the screen is called a line. Therefore, to write a line means to output a line of text.

System.out is a special system object that prints text to the screen. It’s also called the console. The console is one of the most common ways for a program and a person to interact. When a user types commands to a program on the keyboard, and it responds by printing text to the screen, programmers say that the program works with the console.

In other words, working with the console is printing text to the screen and inputting data using the keyboard. So if you hear in the future that a program printed something to the console, that simply means it printed text to the screen.

So it turns out that System.out.println is essentially “Hey, console, print me a line of text.”

4. Examples of printing various data

Let’s play around with console output. We’ll start with the simplest and gradually make it more complex:

Printing numbers

System.out.println(1001);
System.out.println(-15);
Printing numbers

Printing text

System.out.println("Programming is awesome!");
System.out.println("Just kidding — now let’s code.");
Printing text

Printing multiple values at once

Trick: you can combine strings using +. Although it’s better to call it concatenation:

System.out.println("My age: " + 28);
Concatenating a string and a number

This will print:

My age: 28

You can also concatenate several values in a row:

System.out.println("The year is " + 2025 + ".");
Concatenating multiple values

This will print:

The year is 2025.

5. Common mistakes when using System.out.println

Young Jedi often run into the same pitfalls. So that you don’t become the hero of the book “1001 Mistakes in Java,” here’s a list of common gotchas and tips on how to avoid them.

Mistake 1. Forgot to close the string—missing the second quote:

System.out.println("Oops, opened a quote and forgot to close it);

The compiler will complain: "unclosed string literal" — close your strings!

Mistake 2. Missing semicolon


        System.out.println("No ; at the end")

But Java is unforgiving. Fix it—add a semicolon at the end of the line.

Mistake 3. Using the wrong quotes


        System.out.println(‘Error’); // wrong!
System.out.println('Error'); // also wrong!

For strings, always use standard double quotes—like these: ".

1
Task
JAVA 25 SELF, level 1, lesson 2
Locked
Chat message 💬
Chat message 💬
1
Task
JAVA 25 SELF, level 1, lesson 2
Locked
Assembling a sentence from words 📝
Assembling a sentence from words 📝
Comments (21)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
CJ Level 1, United States
17 June 2026
or s
CJ Level 1, United States
17 June 2026
why the italic
CJ Level 1, United States
17 June 2026
ive mastered 8 languages now i need to code jarfiles for minecraft
Muksud Alam Level 4, Bangladesh, Bangladesh
6 June 2026
super analysis and presentation like supernatural kingdom
Eric Yagubyan Level 1, United States
1 June 2026
hey guys do you have to pay for some subscription to use this app for on and forever?
Rajeev LODHA Level 1, India
17 May 2026
hii everyone😀
Kevin Omondi Level 2, Kenya
21 May 2026
hey sir
Coded nyx Level 3
12 May 2026
I love programming
GXLTY - Level 1, United States
25 April 2026
System.out.println("This is cool");
Felix Okoro Level 2, Nigeria
20 April 2026
System.out.println("java is great");
Anonymous #11789481 Level 2, -, Rwanda
16 April 2026
System.out.print("I "); System.out.print("learn "); System.out.print("Java."); System.out.println(); System.out.print("This "); System.out.print("is "); System.out.print("interesting!");