void main
In short: The fixed entry point of every executable Java program — the JVM looks for exactly this method signature at startup, to get going.
In more detail: The exact signature is prescribed: public static void main(String[] args). static, because the method has to be callable with no object created beforehand; String[] args accepts command-line arguments passed to the program at startup.
public class Program {
public static void main(String[] args) {
System.out.println("Hello World");
}
}In Depth
public class Program {
public static void main(String[] args) {
if (args.length > 0) {
System.out.println("First argument: " + args[0]);
}
System.out.println("Hello World");
}
}
// Called from the command line with arguments:
// java Program hello world
// -> args = {"hello", "world"}Every part of the signature public static void main(String[] args) has a mandatory reason: public, so the JVM (which itself sits outside the class) is even allowed to call the method at all. static, because at program start NO object of the class exists yet — so the JVM can’t call an instance method, only a static, class-bound one. void, because the method delivers no return value to the JVM (the program instead signals success/failure via the exit code with System.exit(code), not via return). String[] args finally accepts all command-line arguments the program was started with — for java Program hello world, args contains the two strings "hello" and "world", the program name itself is NOT part of args.
A single class can certainly contain several main methods with different parameters (overloading) — but at program start, the JVM exclusively calls the EXACT signature public static void main(String[] args), all others would just be normal, manually callable methods. Since Java 21, there’s additionally an experimental simplified entry-point syntax with no enclosing class and no public static/args, intended for small learning/scripting programs.