1 · Foundations · lesson 2 of 41
Hello, World
Your first program — and every piece of the required ceremony explained.
Every Java program starts inside a class, and execution begins at a method named main with a very specific signature.
Java
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}- ▸public — visible to the JVM launcher outside this class.
- ▸class Hello — the container; filename must be Hello.java.
- ▸static — no instance is needed to call main.
- ▸void — main returns nothing.
- ▸String[] args — command-line arguments.
NOTE
System.out is a PrintStream; println writes a line to standard output.
Key takeaways
- ✓Filename must match the public class name.
- ✓main has a fixed signature: public static void main(String[]).
- ✓Statements end with a semicolon; blocks use braces.