This tutorial explains how to write a simple Java program and compile and run it in Netbeans IDE.

Netbeans Hello World Java application

Following are the steps required to write and run the Java program

Open Netbeans

  • Open Apache Netbeans IDE 14 from an Apps in Start in Windows

  • It opens Netbeans

  • Create a Java project

Once NetBeans is opened,

  • Go to File -> New Project( Ctrl + Shift +N)
  • Choose the Project Dialog window opened
  • Select Java With Maven project from the Categories panel, and select Java Application from the Projects panel
  • Click the Next button
  • It asks for details Project Name as demoapp, Project location change to the desired workspace folder, and click Finish.
  • Right Click on the project, and the COntext popup opens, Select New, and New, select New Class.
  • It opens a window, enter Class Name as “HelloWorld”.
  • Write a Java simple hello world-class as given below
/**
 *
 * @author Author
 */
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello world in Netbeans IDE");
    }
}
  • Compile and run the project

Normally, We compile the java file and next run the program using the command line.

In Netbeans, It is not required to compile, as it automatically compiles the program.

Right-click on the source code, Select Run File(Shift + F6)

It outputs the message to the console.