Java Hello World for Beginner with NetBeans IDE
- Details
- Written by Nam Ha Minh
- Last Updated on 16 February 2020   |   Print Email
1. Download and Install NetBeans IDE
Go to https://netbeans.org/downloads to download the latest version of NetBeans IDE. You will see the following page:On this download page you see different download bundles. And for Java development only, we can choose either Java SE or Java EE. We’d recommend you to choose Java EE which supports comprehensive Java development (Java EE includes Java SE).So click the Download button in the column Java EE to download NetBeans installer for Java EE development. The file name of the installer program is something like netbeans-8.2-javaee-windows.exe (on Windows).Click on the installer file to start installing NetBeans IDE. You will be asked to install GlassFish and Apache Tomcat server:
2. Create Your First Java Project
Now, let’s create a Java project using NetBeans IDE. Go to menu File > New Project…Under the New Project dialog, choose Java application as shown in the following screenshot:Click Next to advance to the next step. In the New Java Application screen, type Project Name, specify Project Location and the main class:Note that we check the option Create Main Class to generate the main class for the application. Here we specify the package name net.codejava before the class name HelloWorld.Click Finish. NetBeans create the project with a main class very quickly:3. Write Your First Java Code
You can see a code editor for the HelloWorld.java file as shown in the following screenshot:The method main() is the main entry to a Java application. All Java programs start from the main() method. Now, let’s type some code in this method to print “Hello World Java!” on the screen:System.out.println("Hello World Java!");The whole program should look like this:NetBeans is very smart, as it compiles the code instantly while you are typing the code. So if there’s any error, the IDE will inform you by underling the errors with red color, as shown in the following screenshot:If there’s no red marks like this, the code is fine and we’re ready to run the program.
4. Run Your First Java Program
To run the HelloWorld program above, there are several ways:- Go to menu Run > Run Project <ProjectName>
- Click Run Project icon in the toolbar.
- Press F6 key.
- Right click in the code editor, and select Run File (or press Shift + F6).
Related Java Hello World Tutorials:
- How to write, compile and run a hello world Java program for beginners
- How to create, build and run a Java Hello World program with Eclipse
Other NetBeans Tutorials:
- What is NetBeans? - for beginner
- How to Use NetBeans IDE from the Basics
- How to Update License Header for Java files in NetBeans
- 16 NetBeans Shortcut Keys for Code Editing
- 10 NetBeans Shortcut Keys for Code Refactoring
Comments
Thank you bro. I really appreciate.
So what's the next step?