main Method (Java)

The main method is the entry point of a Java program — the first method the JVM runs when you start an application. It always has the signature public static void main(String[] args).

Java

Each part of the signature matters: public so the JVM can call it, static so it runs without creating an object, void because it returns nothing, and String[] args to receive command-line arguments.

A program without a correct main method will compile but won't run as an application.

Examples

Java

public class App {
    public static void main(String[] args) {
        System.out.println("Program started");
    }
}

Output:

Program started

Learn it in a lesson

See also

Back to the Dictionary