Java Reference
In-Depth Information
NetBeans lets you run a project or a single Java class.
•
To run a project, you need to set a main class, which is the fully qualified name of a class with a
main()
method, as you had for the
Welcome
class. In this case, enter
com.jdojo.intro.Welcome
as the main class for the TestApp project. If you run the project, the
com.jdojo.intro.Welcome
class will be run. To run a project, select the Run Project menu item from the Run menu or
press F6 when the project is active in the IDE. You can change the main class for a project using
project properties. I will discuss how to change project properties shortly.
•
To run a file, select a file and select the Run File menu item from the Run menu. Alternatively,
you can select a Java class in the IDE and press Shift + F6 to run it.
To run the
Welcome
class, press F6. The class will be compiled and run. The output will be displayed in the output
pane, as shown in Figure
2-13
.
Figure 2-13.
The Welcome class after adding a statement in the main() method
Adding Classes to the Project
To add a new class, follow these steps.
1.
Select a Java project or a package in the IDE and right-click to access the menu options.
Figure
2-14
shows the menu options when the package
com.jdojo.intro
is selected.