Print Output

Basic Syntax

Print Output

🙋 Need help? Ask an expert now!

Let's examine the print method, which is essential when you want to print text on the console. This method sends anything inside the parenthesis to the output stream, which is why the characters appear on the console. Please study the examples below to see two different ways of printing on the console.

PrintOutputExample.java
package exlcode;

public class PrintOutputExample {

  public static void main(String[] args) {
    // this prints Hello!, Hello World! on the same line
    // and Hello Friends! on a different line
    System.out.print("Hello!");
    System.out.println("Hello World!");
    System.out.println("Hello Friends!");
  }
}

System.out.print() prints one line on the console and System.out.println() prints on the console followed by a new line. The "System" part of the statement accesses all of the methods and classes associated with the System class, which is automatically imported. The "out" part of the statement accesses all of the methods and classes related to output. The "print" or "println" is a method contained inside System.out. The statement we want to print out on the console must be enclosed by double quotation marks.

Printing on the console is another method to debug your source code as we are able to check the value of a variable to see if it works as intended.

Edit Me on GitHub!

Application Question

Which of the following statements will display "Welcome to Java" on the console?