This page shows you how to create a Java project in NetBeans. If you haven’t installed NetBeans yet, start with this other page. In general, you will create a new project for each C112 assignment that requires you to hand in Java. You should follow this method for doing so. In particular, pay attention to the last paragraph on this page. Creating a project with a named default package is not a strategy we will use until Week 8 of the course. Handing in an assignment that contains a Java program with a named default package also creates extra work for me when grading. After I give warnings about this during the Chapter 2 lab assignment, I will deduct points when Java programs are handed in with a named default package.

Java Program / NetBeans Project Basics

After installing NetBeans, an INFO-C112 assignment (the Chapter 1 lab) asks you to run a first Java program: Hello, World! The images below illustrate project creation on my Mac. The process is the same on Windows except the user interfaces will have slight differences in appearance, and the menu bar will not be locked to the top of the screen as on a Mac.

1. After starting up NetBeans, select New Project from the File Menu. When you do that, you’ll see the folder-like icon with a green plus sign by it in the menu. There is a similar icon on the toolbar seen to the left of the menu in my screen capture. You can also just click that icon to make a new project if you prefer.

Select File > New Project

2. Once you select New Project, you’ll enter a dialog. The first step is to select the “Java with Ant” option in the left options box of the dialog. In the right options box, select “Java Application”.  We’l use these options for every Java project in C112. Click Next.

Select Java With Ant and Java Application

3. Change the default project name (it will be JavaApplication1 the first time) to whatever your project is to be called. The assignment will tell you the project name each time in C112. The first assignment’s project name is HelloWorld and is shown here. Capitalization matters, so we will use UpperCamelCase for project names.

Name the project

4. This step is important to pay attention to! By default, NetBeans places the file contain your project’s code in a package with a name derived from a lowercase version of the project name. The Java class will have the same name as the project name.  To match the examples in the text that do not use this “default package” name, we need to delete the “helloworld.” part and just leave “HelloWorld” as the Main Class Name. 

Select the default package name
Delete the default package name

5. At that point, NetBeans will create your project and you can create your Java code.

Create Java code

One quirk of NetBeans is that it by default creates a Java package to contain the program. The book does not immediately address Java packages. Be sure to remember to remove the package name and . before the name of your main class on the second page of the New Project Dialog. If you don’t see “<default package>” in your project view above your .java file, you skipped this step. Delete your project (right click and Select Delete, then check the box in the dialog to remove the files) and try again.