How to write a Hello World program

Create the source file

Save the program as HelloWorld.java. The filename must match the public class name, including capitalization.

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Understand the class

Java code lives in classes. The braces enclose the class body, and statements normally end with semicolons.

Understand main

The JVM begins this program at public static void main(String[] args). Keep this exact signature while learning.

Print output

println prints a value and then starts a new line; print leaves the cursor on the same line.

System.out.print("Hello, ");
System.out.println("Java!");