Create a file called HelloWorld.java. The file name must match the class name exactly, including capitalization. If they don't match, the compiler will reject your code.
Type this into the file:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Every Java program needs at least one class. The public class HelloWorld line declares that class. Inside it, the main method is where execution begins. System.out.println prints text to the console followed by a newline.
Notice the structure: a class wraps everything, and main lives inside the class. You can't write code outside of a class in Java.