DevAcademia
C++C#CPythonJava
  • Java Basics

  • Java Introduction
  • Java Get Started
  • Java Syntax
  • Java Output
  • Java Comments
  • Java Variables
  • Java Data Types
  • Java Type Casting
  • Java Operators
  • Java Strings
  • Java If...Else
  • Java Switch Statement
  • Java Loops
  • Java Math
  • Java Arrays
  • Java Date
  • Java OOP

  • Java Classes/Objects
  • Java Class Attributes
  • Java Class Methods
  • Java Constructors
  • Java Destructors
  • Java this Keyword
  • Java Modifiers
  • Java Non Modifiers
  • Java Encapsulation
  • Java Packages & API
  • Java Inheritance
  • Java Polymorphism
  • Java Super Keyword
  • Java Inner Classes
  • Java Exception Handling
  • Java Abstraction
  • Java Interfaces
  • Java Enums
  • Java User Input
  • Java Quiz

  • Java Fundamentals Quiz
  • Java Basics

  • Java Introduction
  • Java Get Started
  • Java Syntax
  • Java Output
  • Java Comments
  • Java Variables
  • Java Data Types
  • Java Type Casting
  • Java Operators
  • Java Strings
  • Java If...Else
  • Java Switch Statement
  • Java Loops
  • Java Math
  • Java Arrays
  • Java Date
  • Java OOP

  • Java Classes/Objects
  • Java Class Attributes
  • Java Class Methods
  • Java Constructors
  • Java Destructors
  • Java this Keyword
  • Java Modifiers
  • Java Non Modifiers
  • Java Encapsulation
  • Java Packages & API
  • Java Inheritance
  • Java Polymorphism
  • Java Super Keyword
  • Java Inner Classes
  • Java Exception Handling
  • Java Abstraction
  • Java Interfaces
  • Java Enums
  • Java User Input
  • Java Quiz

  • Java Fundamentals Quiz

Loading Java tutorial…

Loading content
Java BasicsTopic 4 of 59
←PreviousPrevNextNext→

Java Output - Complete Guide

Introduction to Java Output

Java provides several ways to display output to the console. The most common methods are through the System class, which contains the out object (PrintStream).

The primary output methods in Java are:

• System.out.print() - Prints without newline

• System.out.println() - Prints with newline

• System.out.printf() - Formatted output

• System.out.format() - Similar to printf

Basic Output Methods

The most frequently used output methods are print(), println(), and printf().

• print() writes text without appending a newline.

• println() writes text followed by a newline.

• printf() allows formatted output using placeholders.

Example
public class OutputDemo {
    public static void main(String[] args) {
        // print() - doesn't add newline
        System.out.print("Hello, ");
        System.out.print("World!");

        // println() - adds newline
        System.out.println("This is on a new line");
        System.out.println("And this is on another line");

        // printf() - formatted output
        String name = "Alice";
        int age = 25;
        System.out.printf("Name: %s, Age: %d%n", name, age);
    }
}
Output
Hello, World!This is on a new line
And this is on another line
Name: Alice, Age: 25

Escape Sequences

Escape sequences let you include special characters in strings:

• \n - Newline

• \t - Tab

• \\ - Backslash

• \" - Double quote

• \' - Single quote

Example
public class EscapeSequences {
    public static void main(String[] args) {
        System.out.println("Newline: First line\nSecond line");
        System.out.println("Tab: Column1\tColumn2\tColumn3");
        System.out.println("Backslash: C:\\Users\\Name");
        System.out.println("Double quote: She said \"Hello!\"");
        System.out.println("Single quote: It\'s working");
    }
}
Output
Newline: First line
Second line
Tab: Column1	Column2	Column3
Backslash: C:\Users\Name
Double quote: She said "Hello!"
Single quote: It's working

Output Best Practices

  • ✅ Use println() for user-friendly output with proper line breaks
  • ✅ Use print() when building output across multiple calls
  • ✅ Use printf()/format() for structured and formatted output
  • ✅ Include meaningful labels in your output for clarity
  • ✅ Use logging frameworks in production instead of System.out
  • ✅ Test on different platforms since line endings may differ
Test your knowledge: Java Output - Complete Guide
Quiz Configuration
4 of 8 questions
Sequential
Previous allowed
Review enabled
Early close allowed
Estimated time: 5 min
Java BasicsTopic 4 of 59
←PreviousPrevNextNext→