
How to Create a New
Project with NetBeans
by Larry Arnoldy
To
use NetBeans, you must tell NetBeans the name of your project and where
the files that you will be working with are located. The first
time that you start NetBeans, it uses a project named Default.
Thereafter each time that you start NetBeans it starts with the project
that was being used the last time the program was shutdown.
Step 1 - Start NetBeans
Double click the desktop
icon

or click on the
Start button and navigate to the
program name.
Step
2 - Create a new Project
Click on the menu item Project and then click on Project Manager in the drop down
list.
Step 3 - Click the New button.
If you have created previous projects
they will be listed on the left side of the Project Manager dialog box.
Project Default will always
be listed. Click on New for
a new project.
Step 4 - Give the project a name
A dialog box will appear in which you
can enter the name of your project. Type over the default name and give
the project a meaningful name and then click
OK. For assignments,
it is a good idea to include the chapter and exercise number in the
name. This is an example for exercise 9 from chapter 2.
Step 5 - Define the location of
the files for the project.
NetBeans uses the term Filesystem for
the directories in which the files for your project are
located.
In order to
tell NetBeans which directories that you need, you must
first mount them as a Filesystem.
Right click on Filesystems in
the left hand window, then
on Mount, then on Local Directory. Make sure that
you used a right mouse click on Filesystems.
Step 6. Determine the directory for
the source files.
A file system dialog box will
appear. Navigate to the directory where you wish to store your files.
It is a good idea to put each exercise in a separate directory. If the
directory does not already exist
click on the
New Directory
icon and give the new folder an appropriate
name by typing over the default
New
Folder name. When doing exercises from the text book, it is a
good idea to
include the chapter and exercise numbers in the directory name. The
name does not have to be the same as the project name, but can be if
you wish. If the directory already exists, simply click on the
directory name.
After you have chosen the directory, click the
Finish button to return.
Step 7 - Create a new Java class file
in the IDE editor.
The basic IDE window should now be
displayed. On the left is the list of
mounted file systems. If the
Runtime
window is showing on the left hand side, then click on
Filesystems. In some cases there
may be more then one filesystem that is displayed. In the
example here, there is only one. The right side is the editor window.
We
have not told NetBeans yet that we wish to edit a file, so it is empty.
To create a new Java source file, right click on the name of the
filesystem in the left hand window. Make sure that you use the right
mouse button..
Step 8 - Create a new Java main
class.
In
the drop down boxes that then appear, click on
New then on
Java Main Class.
Step 9 - Name the class.
Replace the
<default name> with the
name of your class. For exercises from the textbook, it is a good idea
to include the chapter and exercise number in the class name. This
example uses
Ch2_9_Main
as
the name of the class. Do
not add the
.java
extension. NetBeans adds the
.java
extension automatically for you. By convention,
Java class names start with a capital letter, so make sure that the
first character is a letter. They may include letters,
numbers, and underscores. After clicking
Finish, you are ready to edit
your source file.
Step 10 - Edit the source file.
Because we requested a Java main class,
NetBeans uses this template for creating a Java main class. The source
file is displayed in the right
hand
editor window. This template saves some typing, because it already
includes some of the standard code that is usually included in a
Java source file. You can now modify this source file as needed.
Step 11 - Create more Java source
files as needed (optional).
Depending upon your project, you may
need more than one source Java file. If so, proceed as in steps 8
through 10,
except in step 9, choose "Java Class". You will then see the new file
in the Filesystem tree and its tab in the editor window. Click on the
appropriate tab to display the source file.
Step 12 - Edit,
compile, and execute the source file(s).
Return
to How-To Home
Last modified: 13 June 2004