Hello World Program In Java Using NetBeans

By bhagwatchouhan
Hello World Program In Java Using NetBeans

NetBeans is among the most popular IDEs used for Java development. This tutorial provides all the steps required to create the first Java project with Maven in NetBeans. The steps should be the same for all the operating systems including Windows, Ubuntu, etc.

Notes: NetBeans 8 provided options to create simple Java projects without using any kind of build system. NetBeans 11 provides options to create Java projects using either of the build systems among Maven or Gradle. This tutorial provides the steps to create the HelloWorld project using Maven. Also, note that I am using Java 14 and NetBeans 11 for this tutorial.

 

Prerequisites

This tutorial assumes that NetBeans and Java are already installed on the system.  You can follow How To Install NetBeans On Windows. You can also follow How To Install Java 14 On Windows or How To Install OpenJDK 14 On Windows to install the most recent version of Java.

 

Create Java Project

Start the IDE in case it's not running. Now click the File Options on Main Menu -> New Project. It will show the New Project Wizard as shown in Fig 1.

NetBeans 11 - Create Java Project

Fig 1

Select Java with Maven from the Categories option and also select Java Application from Projects option as highlighted in Fig 1. The NetBeans 11 will show a message in the description section to enable appropriate plugins required for Java development, in case it's the first project. Now click the Next Button. On the next wizard, NetBeans will find the corresponding plugins required for Java development as shown in Fig 2.

NetBeans 11 - Find Features

Fig 2

Now click the Download and Activate Button to download and activate the required extensions. The next screen provides options to confirm downloading the nb-javac extension as shown in Fig 3.

NetBeans 11 - Java 8 Support

Fig 3

Click the Next Button to confirm the installation. The next screen asks to accept the License Agreement as shown in Fig 4.

NetBeans 11 - License Agreement

Fig 4

Now click Install Button to start installing the nb-javac extension. It will show the installation progress and the success message as shown in Fig 5 and Fig 6.

NetBeans 11 - Extension Progress

Fig 5

NetBeans 11 - Extension Success

Fig 6

Now click Finish Button to complete the installation of nb-javac extension. The next screen shows the progress of the Java SE activation as shown in Fig 7.

Java SE Activation

Fig 7

Once JAVA SE is activated, we can continue with project configuration as shown in Fig 8.

NetBeans 11 - Project Configuration

Fig 8

Now click the Finish Button to complete the project set up. The project with default package created by NetBeans looks like the one shown in Fig 9.

Java Project

Fig 9

 

Hello Java

In this step, we will write our first program and execute it on the console. Now right-click on the default package and choose Java Class as highlighted in Fig 10.

Create Java Program

Fig 10

The next screen provides options to configure our first Java Class name as shown in Fig 11.

Configure Java Program

Fig 11

Now click the Finish Button to create the class file. It will create the Java class using the default template as shown in Fig 12.

Default Java Class

Fig 12

Now update the class file to print Hello World on the console as shown below.

package com.helloworld.core;
public class HelloJava {
public static void main( String[] args ) {
System.out.println( "Hello World !!" ); } }

Now right-click on the HelloJava.java file in the Projects Window on the left panel. Also, click on Run File to execute the program as shown in Fig 13. You can also select the File on Projects Window and press Shift + F6 to execute the program.

Run Java Program

Fig 13

It will take some time for Maven to download all the required dependencies for the first time. Finally it shows the output after compiling and building the project as shown in Fig 14.

Program Output

Fig 14

These are the basic steps required to write and execute Java programs with Maven using NetBeans 11.

 

Summary

This tutorial explained the steps required to create the first Java project with Maven using NetBeans 11 and also explained to write and execute the Java programs.

Share this blog:

Profile picture for user bhagwatchouhan
bhagwatchouhan