When using JavaFX we override the method start which launches the application.
@Override
public void start(Stage primaryStage ) {}
I've found that java compiler understands that start is the startingpoint when there's no main method. A main method seems to be unnecessary. Are there reasons to still be implementing a main ?
Are there also functional reasons to still implement a main method?
Note: My answer assumes OpenJDK/OracleJDK. I don't know if other vendors behave the same way.
The documentation quoted by others focuses on the JavaFX Packager tool which no longer exists1. It's worth noting that the tool does not seem to be necessary (at least for Java 10 and 11). The only thing required is that the JavaFX libraries be present and that the designated main class extends Application
; then you don't need the main
method regardless of how the code is assembled.
Are there also functional reasons to still implement a main method?
In a normal JavaFX application, I'd say no. Pretty much any initialization you'd want to do in main
could be done inside Application.init
instead. You also have access to the command line arguments via Application.getParameters
.
P.S. the most important question why does the compiler accept start as a starting point.. It's against my programming neurotism
See my answer here for details about the internal launch procedure for JavaFX (at least for 10 and 11) applications.
Also, the compiler doesn't "accept start as a starting point". The compiler just compiles the code and sees start
—and main
—the same as any other method. It is the runtime that searches for main
and invokes it. That said, the linked answer goes over how start
(and JavaFX applications in general) gets special treatment.
1. The packager tool was removed in Java 11. However, there is a possible replacement coming: jpackager.