Quick revision
The short answer
The classic entry point is public static void main(String[] args) in the class we name, and public static void main(String... args) is the same signature, so it works. Before Java 25, private static void main(String[] a) and static int main(String[] a) were not launchable, and the launcher reported that no suitable main method was found. Since Java 25 (JEP 512), the launcher also accepts non-private, non-static and no-argument main methods, but a private main or one that returns a value is still not an entry point.
What to remember
In this answer, we saw that the classic entry point is public static void main(String[] args), that String... is the same signature, and that before Java 25 private or non-void main methods were rejected because no suitable main method was found. Java 25's JEP 512 also accepts non-private, non-static and no-argument main methods, with a fixed order of preference, but private and non-void methods are still not entry points. The class comes from the command line, the jar manifest or a source file, and the JVM exits when all non-daemon threads finish or System.exit is called, with status 1 if main throws.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The classic entry point is public static void main(String[] args) in the class we name, and public static void main(String... args) is the same signature, so it works. Before Java 25, private static void main(String[] a) and static int main(String[] a) were not launchable, and the launcher reported that no suitable main method was found. Since Java 25 (JEP 512), the launcher also accepts non-private, non-static and no-argument main methods, but a private main or one that returns a value is still not an entry point.
Why this question is asked
Every Java program starts at a main method, and most of us type its signature from memory without thinking about which parts are required. The rules matter when an IDE template is wrong, when a framework generates code, and now that Java 25 has relaxed them, when we read newer code that looks nothing like the classic form. Interviewers ask about the variants to see whether we know the exact launch protocol, how the launcher finds the class, and when the JVM actually exits. In this answer, we will recap the classic form, test each variant from the question, look at what Java 25 changed, see where the launcher finds the class, and finish with how the program ends.
1The Classic Form and Why Each Word Is There
For most of Java's history, the launcher looked for exactly one method in the class we named: public static void main(String[] args). Each part has a reason. public, so the launcher, which is outside our class, may call it. static, so it can be called without creating an object first. void, because the program reports its result through the exit status, not a return value. And a String array for the command-line arguments.
The parameter name does not matter, and neither does the array syntax: String[] args, String args[] and String... args all declare the same parameter type, because varargs is just an array parameter with a flag that lets callers pass loose values. Modifiers such as final or synchronized on main are allowed too.
2Testing the Variants From the Question
Here are the three variants and what happens when we run each with java App on the classic rules, before Java 25.
The private version fails because the launcher may not call a private method. The int version fails because the protocol requires void, since the JVM has no place to put a returned value. The exact error text has changed between releases, so check your version for the wording, but both are rejected.
3What Java 25 Changed
Java 25 finalized JEP 512, compact source files and instance main methods, which relaxed the launch protocol to make small programs simpler. The launcher now also accepts a main method that is not static, that has no parameters, or that is package-private or protected instead of public. The only things it still rejects are private methods and methods that do not return void.
When a class has more than one candidate, the launcher picks in a fixed order: a main method with a String array parameter is preferred over one with no parameters. If the chosen method is static, it is simply called. For an instance main, the launcher first creates an object with the class's non-private no-argument constructor and then calls main on it.
| Declaration | Before Java 25 | Java 25 |
|---|---|---|
public static void main(String[] a) | Yes | Yes |
public static void main(String... a) | Yes | Yes |
static void main(String[] a) | No | Yes |
void main() | No | Yes, on a new instance |
private static void main(String[] a) | No | No |
static int main(String[] a) | No | No |
So for the question's variants, String... works everywhere, while the private and int versions remain failures even on Java 25, because they break the two rules that are left.
4Where the Launcher Finds the Class
There are three ways to tell the launcher which class to start. java com.acme.App names the class directly, and the class path tells the launcher where to find it. java -jar app.jar reads the Main-Class attribute from the jar's manifest; a Spring Boot fat jar names Spring Boot's own launcher class there, which then starts the application class named in Start-Class. And java App.java runs a source file directly: the launcher compiles it in memory and runs the first top-level class it finds, and since Java 22 it can also compile other source files that the program refers to.
5How the Program Ends
Returning from main does not necessarily end the program. The JVM exits when the last non-daemon thread finishes, or when some code calls System.exit or Runtime.halt. The main thread is just one non-daemon thread; if main starts a non-daemon thread, such as a server's worker or a thread from an executor with default settings, the JVM keeps running after main returns until that thread ends.
Daemon threads, created with setDaemon(true), do not keep the JVM alive; when only daemon threads are left, the JVM exits and they are stopped. The exit status is 0 when the program ends normally, the value passed to System.exit when that is called, and 1 when main ends with an uncaught exception, as the FAQ below explains.
6Follow-up questions
What exit code does the JVM return if main throws an exception?
The launcher prints the stack trace through the main thread's uncaught exception handler and then ends with exit status 1. If other non-daemon threads are still running, the JVM first waits for them to finish, and the status is still 1. An uncaught exception in some other thread does not change the exit status; that thread dies, and if main returned normally, the program exits with 0 once the other non-daemon threads end.
Can main be declared in an interface or an enum?
Yes. Any class or interface can declare a public static void main(String[] args), including enums, records and interfaces, and the launcher will run it when we name that type. Java 25's instance main methods need a class the launcher can instantiate, so an instance main in an interface or abstract class is not launchable.
Does Spring Boot change how main works?
No. A Spring Boot application has an ordinary main that calls SpringApplication.run. The JVM keeps running afterwards because the embedded web server starts non-daemon threads, and the application stops when those threads end, for example on SIGTERM through the shutdown hooks.
7Conclusion
In this answer, we saw that the classic entry point is public static void main(String[] args), that String... is the same signature, and that before Java 25 private or non-void main methods were rejected because no suitable main method was found. Java 25's JEP 512 also accepts non-private, non-static and no-argument main methods, with a fixed order of preference, but private and non-void methods are still not entry points. The class comes from the command line, the jar manifest or a source file, and the JVM exits when all non-daemon threads finish or System.exit is called, with status 1 if main throws.
Open with
The classic entry point is public static void main with a String array. It is public so the launcher can call it, static so no object is needed, and void because results go out through the exit status.
Then, if they want more
String varargs is the same parameter type, an array, so public static void main with String dots works on every version.
Before Java 25, private static void main fails, because the launcher cannot call a private method, and static int main fails, because the protocol requires void; the launcher says it cannot find a suitable main method, with wording that varies by version.
Java 25 finalized JEP 512, which relaxed the protocol: main can now be package-private or protected, can be an instance method, and can have no parameters, and the launcher prefers the String-array form over the no-argument one, creating an object with the no-argument constructor for an instance main.
But private and non-void main methods are still not entry points, so those two variants fail even on 25. The class comes from the command line, from the jar manifest's Main-Class with java -jar, or from a source file with java App.java.
Returning from main does not end the JVM by itself; it exits when all non-daemon threads are done or someone calls System.exit. If main throws, the stack trace is printed and the exit status is 1, after any remaining non-daemon threads finish.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 25, Java 21, Java 22
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What exactly must a classic Java main method look like for the java launcher to start...": https://scrivio-interview-library.netlify.app/java/classes-and-objects/8fc6a7171e/