Lesson 3 / 39

Your First Program

Write a Hello World class, understand the public static void main entry point, then compile with javac and run it on the JVM.

By · 15 years in web development · Updated 1 Oct 2026

Hello, World

Every application entry point is public static void main(String[] args). The file name must match the public class name — Hello.java.

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

Output:

Hello, World

Compile & run

javac produces Hello.class; java launches the JVM with that class. Since Java 11 you can also run a single file directly without compiling first.

javac Hello.java
java Hello

# or, one step (Java 11+):
java Hello.java

Quick check

Quick check: What does `javac` produce from a `.java` file?

  • Native machine code for your CPU
  • Platform-neutral bytecode in a .class file
  • An executable .exe
  • Nothing — Java is interpreted line by line
Answer

Platform-neutral bytecode in a .class file — The compiler emits JVM bytecode; the JVM then executes (and JIT-compiles) it at runtime.