← Java tutorial

Java

Introduction to Java

Java is a statically-typed language — every variable's type is fixed and checked before the program even runs, catching a whole category of mistakes before your code ever executes, not while it's running.

Example: the minimum a Java program needs

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

Every Java program lives inside at least one class, and execution starts from a special main method — unlike Python or JavaScript, there's no way to run a bare line of code outside a class at all. This ceremony exists because Java is fundamentally class-based: even "hello world" has to live somewhere, and that somewhere is always a class.

Example
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}
Output
Hello, world!