Lesson 1 of 510 minModule progress 0%

Module 2: Output, Input, Variables, and Types

Printing Text and Numbers with `System.out.println`

Use console output to display strings, numbers, and quick feedback while you learn.

Author

Java Learner Editorial Team

Reviewer

Technical review by Java Learner

Last reviewed

2026-04-16

Java version

Java 25 LTS

How this lesson was prepared: AI-assisted draft, edited by hand, and checked against current Java 25 documentation and runnable examples.

Learning goals

  • Print text and numbers clearly
  • See the difference between plain text and calculated output
  • Use output as a simple debugging tool

Why this matters: Output is how you see what your program is doing. Early on, printing values is also your fastest debugging technique.

Strings vs numbers: Text goes in double quotes, but numbers do not. System.out.println("5") prints a string, while System.out.println(5) prints a number.

You can print expressions too: Java evaluates expressions before printing them, so System.out.println(2 + 3) prints 5.

Good habit: Print small checkpoints while learning so you can see program state change line by line.

Runnable examples

Print text and a number

public class Main {
    public static void main(String[] args) {
        System.out.println("Java practice");
        System.out.println(25);
    }
}

Expected output

Java practice
25

Print a calculation

public class Main {
    public static void main(String[] args) {
        System.out.println(7 + 4);
        System.out.println("Total: " + 11);
    }
}

Expected output

11
Total: 11

Common mistakes

Using quotes around a number you want to calculate with

Keep numbers unquoted when they are meant to be numeric values.

Mini exercise

Print your age on one line and the sum of 8 + 5 on the next line.

Summary

  • Printing is your first feedback loop.
  • Java can print both text and evaluated expressions.

Next step

Now that you can print values, you need a place to store them: variables.

Sources used

Advertisement

Lesson check

What does `System.out.println(2 + 3)` print?

Next lesson →