How to Create and Run a Java Project in NetBeans IDE

If you’re learning Java or building full-fledged applications, NetBeans IDE is one of the best environments to get started. It’s a free, open-source IDE developed by Apache, designed specifically for Java — with built-in tools for coding, debugging, and managing projects efficiently.

In this guide, we’ll show you exactly how to create, compile, and run a Java project in NetBeans IDE on your system. Whether you’re using Windows, macOS, or Linux, the steps are nearly identical.

What You’ll Need Before You Start

Before diving in, make sure you’ve got the basics covered:

  • NetBeans IDE installed (preferably version 20 or later).
  • Java Development Kit (JDK) — at least JDK 17 for modern projects.
  • A computer running Windows, macOS, or Linux.

If you haven’t installed NetBeans yet, download it from the official Apache site: https://netbeans.apache.org/download/

During installation, ensure the setup detects your JDK automatically. If not, you can manually specify the JDK path later in the IDE.

Step 1: Launch NetBeans IDE

After installation, open NetBeans IDE from your desktop or start menu.
When it first loads, you’ll see a clean workspace with options like:

  • Projects (on the left sidebar)
  • Files and Services tabs
  • A Start Page with shortcuts for new projects and tutorials

This workspace is where all your Java projects will live.

Step 2: Create a New Java Project

Now let’s create your first Java project.

  1. Click on File → New Project (or press Ctrl + Shift + N).
  2. In the dialog box, choose:
    • Category: Java with Ant or Java with Maven
    • Project Type: Java Application
  3. Click Next.
  4. Enter your Project Name (e.g., HelloWorldApp).
  5. Choose a Project Location — where your files will be saved.
  6. Make sure Create Main Class is checked, and give it a name (for example, helloworldapp.HelloWorld).
  7. Click Finish.

NetBeans will automatically generate your project structure and create a default Java file with the main() method.

Step 3: Explore the Project Structure

Once created, you’ll see your project listed in the Projects panel on the left side.
Click the arrow next to it to expand the folders:

  • Source Packages → Contains your Java source files (e.g., HelloWorld.java)
  • Libraries → Lists the JDK and other dependencies
  • Test Packages → For unit testing (optional)
  • build.xml → Ant build file (if using Ant)

The generated Java file usually looks like this:

package helloworldapp;

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, NetBeans!");
    }
}

Step 4: Run Your Java Project

Running your Java project is as simple as clicking a button.

  1. Click the Run Project icon on the toolbar — or press Shift + F6.
  2. The Output Window (usually at the bottom) will show the result.

You should see something like:

run:
Hello, NetBeans!
BUILD SUCCESSFUL (total time: 0 seconds)

Congratulations! You’ve just created and executed your first Java project in NetBeans.

Step 5: Customize and Experiment

Now that your project is running, you can start experimenting:

  • Add more print statements: System.out.println("Java development made easy!");
  • Create new classes:
    Right-click your Source Packages folder → New → Java Class → Name it (e.g., Calculator.java).
  • Refactor your code:
    NetBeans supports intelligent refactoring, syntax highlighting, and even debugging — so you can focus more on logic than setup.

Step 6: Build and Clean Your Project

NetBeans uses a build system (Ant or Maven) that automates compiling and packaging your code.

To build your project manually, go to:

  • Run → Build Project (or press F11)

To clean old compiled files and rebuild from scratch, use:

  • Run → Clean and Build Project

Once built, you’ll find your .class and .jar files in the dist/ folder inside your project directory.

Step 7: Create a Runnable JAR File (Optional)

If you want to distribute your Java app, you can package it into a single executable JAR file.

  1. Go to the Projects tab.
  2. Right-click your project and select Clean and Build.
  3. NetBeans will generate a runnable .jar file in: /dist/YourProjectName.jar

You can now run it directly from the terminal or command prompt:

java -jar YourProjectName.jar

This is great for sharing your Java application or deploying it on another system.

Step 8: (Optional) Debug Your Project

NetBeans includes a powerful debugger that helps you track down bugs easily.

  1. Click on the left margin next to any line to set a breakpoint.
  2. Click the Debug Project button or press Ctrl + F5.
  3. The IDE will pause execution at that line, letting you inspect variable values and step through code.

Debugging in NetBeans is intuitive — perfect for learning how your Java logic flows.

Wrapping Up

And that’s it! You’ve successfully learned how to create, build, and run a Java project in NetBeans IDE.

NetBeans is a powerful all-in-one environment that streamlines Java development — from writing your first “Hello, World” program to building enterprise-level applications.

Once you’re comfortable with the basics, you can explore advanced features like Maven project management, integrated Git support, and JavaFX UI development — all built right into the IDE.

Posted by Arpita

With a background in Computer Science, she is passionate about sharing practical programming tips and tech know-how. From writing clean code to solving everyday tech problems, she breaks down complex topics into approachable guides that help others learn and grow.

X