← Back to Chapters

Java Output Methods

?️ Java Output Methods

? Quick Overview

Java provides multiple ways to display output on the screen. These output methods are mainly used for debugging, displaying results, and user interaction.

? Key Concepts

  • System.out.print() prints output without a new line
  • System.out.println() prints output with a new line
  • System.out.printf() prints formatted output

? Syntax / Theory

The System.out object represents the standard output stream connected to the console.

? Code Examples

? View Code Example
// Using print method
System.out.print("Hello");
System.out.print(" World");
? View Code Example
// Using println method
System.out.println("Hello");
System.out.println("World");
? View Code Example
// Using printf for formatted output
int age = 20;
System.out.printf("Age is %d years", age);

? Live Output / Explanation

Output:

Hello World
Hello
World
Age is 20 years

✅ Tips & Best Practices

  • Use println() for readable output
  • Use printf() for formatted data
  • Avoid excessive console output in production

? Try It Yourself

  • Print your name using all three methods
  • Display marks using formatted output
  • Experiment with multiple variables