Java Output (println)
Java output means displaying information from a program on the screen. The most common beginner-friendly way to output something in Java is System.out.println().
You can use output to show messages, results, labels, and simple program progress while your code runs.
Using System.out.println
The statement System.out.println() prints a value, then moves the cursor to the next line. The text you want to print is placed inside the parentheses.
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Java!");
System.out.println("This appears on a new line.");
}
}
Output:
Hello, Java!
This appears on a new line.
How It Works
The word System refers to Java’s standard system class. The out part represents the standard output stream, which usually means the console or terminal. The println method prints the value you give it and then adds a line break.
For now, you do not need to memorize every internal detail. You should recognize System.out.println() as the standard way to show output in simple Java programs.
Printing Text
Text in Java is written between double quotes. This kind of text value is called a string.
public class Main {
public static void main(String[] args) {
System.out.println("Java is case-sensitive.");
System.out.println("Strings use double quotes.");
}
}
Output:
Java is case-sensitive.
Strings use double quotes.
The quotes are part of the Java code, but they are not printed. Only the characters inside the quotes appear in the output.
Printing Numbers
You can also print numbers. Numeric values do not need quotes.
public class Main {
public static void main(String[] args) {
System.out.println(25);
System.out.println(10 + 5);
}
}
Output:
25
15
In the second statement, Java evaluates 10 + 5 first, then prints the result.
println Adds A New Line
Each call to println ends with a line break. That is why two println statements produce two separate output lines.
If you want to print without automatically moving to the next line, use System.out.print() instead.
public class Main {
public static void main(String[] args) {
System.out.print("Java ");
System.out.print("Output");
System.out.println(" Lesson");
}
}
Output:
Java Output Lesson
The two print statements stay on the same line. The final println prints its text and then ends the line.
Common Mistakes
- Use an uppercase
SinSystem. - Use lowercase
outandprintln. - Put text inside double quotes, like
"Hello". - End the statement with a semicolon
;. - Keep the statement inside the
mainmethod.
Takeaway: use System.out.println() when you want Java to display something and then move to the next output line.
