At the end of last semester, I got together with a group of other CSC professors at Villanova to discuss the Algorithms & Data Structures I, II, and III curriculum. One of the topics of this meeting was how to introduce the students to using an IDE (wikipedia link). After a bit of research, the choice was made to go with the open source NetBeans IDE.

While I plan on covering aspects of NetBeans in class, I figured it’d be useful to have a written explanation for my students to refer back to. The NetBeans provided quick start guide is good, but it’s largely geared towards existing developers comfortable with a Java project structure. So over the course of a few blog entries, there are a few topics I want to highlight that are relevant to the projects in my class.

Installation

Installation, however, is not one of the topics I want to cover. To be blunt, I run Linux (regrettably most of my students don’t) and I don’t have a Windows box around to figure out the instructions for that platform. Instead, I’ll simply link to their download page and their install instructions. I suggest that my students download the “Java SE” download bundle from their download list (the “Java” bundle contains a number of extra features that are not used in class, so not including them will limit the amount of noise and distractions in the UI).

Creating a Project

NetBeans, or more generally most IDEs, aren’t used in the same way as a simple text editor. Instead of just opening one file to edit at a time, you first set up some sort of context around the source code. This is typically called a “project”, but don’t be surprised to see words like “module” or “workspace” used in a similar fashion.

Organizing code into projects has a number of benefits. A project keeps related classes linked. For instance, an online store would need classes such as a ShoppingCart, User, PurchaseItem, and so on. Keeping all of these classes in the same project will allow them to “see” each other and be used together for the application. If this seems confusing at first, don’t worry; many students are not introduced to multi-class programs until the basics have been covered. To my students specifically, I can vouch for the fact that this should be clear as our semester progresses.

Creating a new project in NetBeans starts at the File -> New Project menu. This kicks off the project creation wizard.

Step 1

NetBeans - Create a Project - Step 1

The first step is to select a template for the type of project you’re creating. While there are a lot of options to choose from, many are just subtle variations on others. The default (Java -> Java Application) is a good starting point to get an empty project. Make sure this is selected and press Next.

Step 2

NetBeans - Creating a Project - Step 2

The next step is to specify where the project files should be created and stored. You’ll be asked for the following things:

  • Project Name – This is usually just a user-friendly name you give to your project. NetBeans, however, also uses this as the name of the project directory (more on that later). For now I’ll just use the typical programming standby of “HelloWorld”.
  • Project Location – This is a bit misleading. This is the root of where your specific project directory will go (again, more on this later). My suggestion for my students is to create a new directory (i.e. folder) to specify here that all class project will be stored in. For example, C:\Documents and Settings\jdobies\csc1052. Don’t be confused by my screenshot; Linux directories look a little different than on Windows.
  • Project Folder – This is automatically determined by NetBeans (and annoyingly can’t be changed) by using the Project Name as the name of the directory inside of the Project Location. So given the above two examples, the project folder will be created as C:\Documents and Settings\jdobies\csc1052\HelloWorld.

A small clarification of my suggestion from above: Specify the same Project Location (i.e. the csc1052 directory) for all projects for the semester, using a different Project Name each time to reflect each project. This way, all project code will be located in the same place, organized in folders based on each individual project.

I also suggest unchecking the “Create Main Class” option. It’s simply a shortcut to making a class for you, but that’s easy enough to do later. Personally, I’d rather start with an empty project and go from there.

Once all of these values are specified, press Finish to create the project.

What Just Happened?

NetBeans did a lot of stuff behind the scenes. I think it’s important to take a quick look to see what that process just gave us. Below is a screenshot of the contents of the directory I used in the Project Location field during the project creation wizard.

NetBeans - Create a Project - Project Files

Ignoring my other projects, notice the highlighted HelloWorld directory which was created by NetBeans (again, the directory name was taken from the Project Name in the wizard). NetBeans creates three additional directories inside of the project directory.

  • nbproject – Contains the files NetBeans needs to store information about the project. This can be safely ignored; you won’t need to directly interact with these files. However, keep in mind that directory and its contents are only needed by NetBeans; don’t get confused and think these are part of your project (so they don’t need to be submitted to your professor).
  • src – The directory name “src” is the typical abbreviation for “source code” and is where the actual code for your project will go. NetBeans will automatically put most classes in here for you, but it’s important to know where they ultimately end up (I’ll come back to this later when we create a class).
  • test – This is another typical convention seen in many projects. Often, code that is used to automatically test your application is kept separate from the product code itself (don’t mistake that to mean it is any less important). Testing is a huge topic so I won’t go into any more detail here.

The other two files shouldn’t need to be edited either. The short answer is that NetBeans will use them to compile and run your project, so don’t touch them. :)

Now What?

Once the project is created, you’re dropped to the main NetBeans screen. The next steps will be to create a class, compile, and run the main method from inside of NetBeans. I’ll cover all of that in the next post.

One Response to “Getting Started with NetBeans – Creating a Project”


  1. Tushar Joshi

    Hi,

    I appreciate your efforts to make the NetBeans IDE experience for new developers easy. I read in your article that you will not be providing any screenshots and instructions for Windows Installation of NetBeans IDE. I can help you here as I also maintain a blog for beginners and post tutorials for many environments. Please drop your concept to me in mail and I can post a similar tutorial for you, done in Windows XP environment with screenshots.

    Please visit the blog http://netbeanside61.blogspot.com to check some earlier tutorials I have posted.

    with regards
    Tushar Joshi, Nagpur