Hello, World

A class with a main method, and System.out.println.

Runs in Zerethon IDE · Java 25 Official Java documentation ↗
Main.java
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
        System.out.println("Sum: " + (2 + 3));
        System.out.printf("%s has %d letters%n", "Java", 4);
    }
}

Output

Hello, World!
Sum: 5
Java has 4 letters
  • The file Main.java must declare public class Main — the file name and the class name match.
  • The program starts in public static void main(String[] args).
  • println ends the line, print does not; printf formats (%d whole number, %.2f decimals, %s text, %n newline).
  • Watch the brackets: "Sum: " + 2 + 3 is "Sum: 23" because + joins text from left to right.