It is possible to compile and run the main class straight from NetBeans IDE. The primary reason for executing the main class is fairly obvious, that is, to test that modifications made in the software are actually what the coder(s) intended.
It is necessary to have a project in order to create a class, so if you are unsure how to do this, please check the Creating a Java project using Wizard recipe. However, when naming the project, enter RunMainClassApp
.
With the main class open, enter the following line of code inside of the main()
method:
System.out.println("Main class output");
Then right-click inside the Java editor of the Main.java
file and select Run File.
NetBeans will always show the Run File option for a Java class that contains the main method.
After Run File is selected, NetBeans will then compile and execute it. The output, if any, of the main class will be shown in the Output view.
For this example, the output is: Main class output...