Hello World in Java

From the Java cheat sheet · Getting Started · verified Jul 2026

Hello World

The classic entry point, plus the simplified launch form finalized in Java 25.

java
// Quick Reference
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
💡 Class name must match the file name for a public class (Main -> Main.java).
⚡ System.out.println() prints with a trailing newline; use print() without.
📌 Java 25 compact source files let beginners skip the class/static/args boilerplate.
🟢 %n is the platform-independent newline in printf, preferred over \n.
basicsmain

Continue with Java

Save the full cheat sheet or work through every related task.

More Java tasks

Back to the full Java cheat sheet