The main() method is the entry point of a standalone Java program: the JVM finds it in the class you launch and starts running your code there. The classic signature is public static void main(String[] args). Since Java 25, a simpler form without public, static or the args parameter is also allowed.
When main returns and no non-daemon threads are still running, the JVM exits.
When you run java Hello, the JVM loads the class Hello, links and initialises it, then looks for a launchable main method and calls it. Everything else in the program is reached from there: you create objects, call other methods and start threads from main.
A class without a launchable main can still be loaded as a library, but java reports that no main method was found when you try to run it. Libraries, servlets and framework-managed components have no main of their own. Frameworks such as Spring Boot provide a main that bootstraps them.
Each keyword has a reason in the classic form:
| Part | Why it is there |
|---|---|
public | The launcher must be able to call it from outside the class |
static | No object exists yet, so the method belongs to the class |
void | The method returns nothing; the exit code is set with System.exit or by an uncaught exception |
main | The fixed name the launcher looks for |
String[] args | Command-line arguments, separated by spaces, as strings |
String... args is equivalent to String[] args. The parameter name is free, so argv works too. Overloading main with other parameter lists is legal, but the launcher uses only the recognised forms.
Java 25 (an LTS release) finalised instance main methods and compact source files (JEP 512), which were previews in earlier releases. The launcher now selects a main method in this order:
static void main(String[] args)static void main()void main(String[] args) (instance method, class needs a non-private no-argument constructor)void main() (instance method)The method must not be private. A beginner program can therefore be a single source file with no class declaration:
Run it with java Hello.java. In a compact source file the compiler wraps the top-level methods and fields in an implicit final class. IO.println is a small console helper in java.lang introduced for this purpose in Java 25. Production code, libraries and anything built with Maven or Gradle still normally uses an explicit class and the classic signature, which works on every Java version.
main completes normally and threads finish. Call System.exit(n) for a different code. Avoid System.exit in library code.main prints a stack trace and ends the main thread. The JVM exits with code 1 once no other non-daemon threads remain.main may declare throws Exception, which is fine for small tools.args is never null. args.length is 0 when none were given. Parse options with a library such as picocli for anything beyond a couple of values.Error: Main method not found in class X: the method name, parameter or modifiers do not match any supported form (for example public static void main(String args)).NoSuchMethodError: main on older Java: you used an instance or no-argument main, which needs Java 25 or a preview flag on earlier releases.ClassNotFoundException or Could not find or load main class: wrong class name, wrong package, or wrong classpath. Use the fully qualified name, for example java com.example.App.main in a JAR: set the Main-Class entry in the manifest, then run java -jar app.jar.The JVM calls it before any object exists, so it cannot be an instance method. In Java 25 the launcher can create an instance itself when you write an instance main.
Yes, by overloading, but only the recognised signatures are used by the launcher. Other overloads are ordinary methods.
Yes. You choose which class to launch, and each class may have its own main, which is useful for small demos and tests.
Standalone applications do. Web applications, plugins and test frameworks run inside a host that has its own entry point.
main() is where the JVM begins running a Java application. Use public static void main(String[] args) for portable code, and the simplified instance or no-argument forms on Java 25 and later for small programs and teaching. Remember the exit-code rules, validate args, and launch the right class name or manifest entry.