Question

The methods outside the main method are not mentioned in main method. The main method only contain launch(args);

I thought it need to call the methods outside the method that make it work in the program?

So how does launch(args) work?

Was it helpful?

Solution

If you open a template of JavaFX in Netbeans it have a JavaDoc explaining it:

/**
 * The main() method is ignored in correctly deployed JavaFX application.
 * main() serves only as fallback in case the application can not be
 * launched through deployment artifacts, e.g., in IDEs with limited FX
 * support. NetBeans ignores main().
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}

So essentially, it shouldn't even be called as it is JavaFX, however if it is called then it will just pass the command line arguments (args) to the javafx.application.Application.launch which will open the JavaFX as expected.

In case you are still wondering how does the launch works, then you probably should check its source code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top