Entry point classes
suggest changeA Java entry-point class has a main method with the following signature and modifiers:
public static void main(String[] args)
Sidenote: because of how arrays work, it can also be (String args[])
When the java command starts the virtual machine, it loads the specified entry-point class and tries to find main. If successful, the arguments from command line are converted to Java String objects and assembled into an array. If main is invoked like this, the array will not be null and won’t contain any null entries.
A valid entry-point class method must do the following:
- Be named
main(case-sensitive) - Be
publicandstatic - Have a
voidreturn type - Have a single argument with an array
String[]. The argument must be present and no more than one argument is allowed. - Not be generic: type parameters are not allowed.
- Have a non-generic, top-level (not nested or inner) enclosing class
It is conventional to declare the class as public but this is not strictly necessary. From Java 5 onward, the main method’s argument type may be a String varargs instead of a String array. main can optionally throw exceptions, and its parameter can be named anything, but conventionally it is args. These are the classic requirements. Java 21 and later also accept simpler instance main methods; that form was standardized in Java 25.
JavaFX entry-points
Oracle JDK 8 through 10 can also launch a JavaFX application directly. JavaFX was removed from the JDK in Java 11, so later releases need JavaFX on the module path. JavaFX is documented in the JavaFX tag, but a JavaFX entry-point must do the following:
- Extend
javafx.application.Application - Be
publicand notabstract - Not be generic or nested
- Have an explicit or implicit
publicno-args constructor