CS102 Spring
2008
Lab # 0
Learning the NetBeans IDE
The main purpose of this initial laboratory exercise is to acquaint
you with
- your new CS account,
- the new Linux platform in
the Asprey (and Intro) Lab(s),
- the NetBeans IDE, and
- the procedure for submitting your work electronically.
You
will create a NetBeans project within the cs102 course directory of
your CS account. The program you write will itself be very simple,
because the goal of this lab is to learn to use your CS account to
create, compile, execute, print, and submit your work electronically
for grading.
How to get started
- Use your new CS account to login to one of the Linux-based machines in the Asprey (or Intro) Laboratory.
You will be able to create your own directory structure within this
account, and you will be able to save and retrieve your work between logins.
- Create a new directory named cs102 in
your home directory, and set the permissions so that only you can
access the the contents of this directory. To do this, type the
following commands at the Linux prompt ($):
$ mkdir cs102
$ chmod 700 cs102
- From
the Applications menu in the upper left corner of the Gnome desktop,
select Programming, then NetBeans. You may also access NetBeans by
bringing up a terminal window and typing netbeans&
after the command line prompt.
- When NetBeans loads, you will be presented with a welcome screen. (You may wish to run through the tutorial
material present here at some later convenient time.)
- Left-click
your mouse on File at the left
of the menu bar displayed at the top of the screen. Select New Project from the drop-down menu that appears.
- A new
window will appear with side-by-side menus labeled Categories and Projects. The Category selection General will appear
highlighted. Move your mouse to the
selection Java Application in the Projects menu and left-click. When it is highlighted, left-click on
the Next button at the bottom of the window.
- The
next window that appears has text fields labeled Project Name, Project
Location, and Project Folder. Each of these
fields will contain a default value.
- Change the Project Name to Lab0.
- Change the Project Location to the cs102 directory you created in step 2.
- The Project Folder
name will change to be consistent with the project name you select.
- Below these three text fields are two
choice boxes and a text field for naming the class holding the main
function. Since the first class you
create in a project (and the only class in this laboratory exercise) is
the class holding the main method, you will leave both of these choices
set. The default name used by NetBeans for the class holding the main method is Main. The package and class name are shown in
the text field. You may change the
class name to something else if you desire.
- When you have selected a name for your
project (and possibly changed the name of the application class), you will
left-click on the Finish button at the bottom of the window.
- The
main edit window will now appear. The
Projects window will appear at the upper left. The project Lab1 will be open and will
list four packages: Source Packages, Test Packages, Libraries, and Test
Libraries. Only the Source Packages
will be of interest initially. It
will be open and show the package you created and the first class. The class Main
will be highlighted, and the skeleton produced by the ant build will appear
in the edit window in the upper right.
The Navigation Window below the Projects window allows you to select
a class or method name and move directly to that class or method in the
edit window. The window at the
bottom is used for displaying compilation information, error messages, and
output data directed to the console.
- Complete
the program. In the edit window for Main.java, replace the comment in
the body of the main() method (note: not the constructor for class
Main) with an appropriate println() statement. The result should be a
main() method that looks something like this: (feel free to customize
your "Hello, World" message...)
public static void main(String[] args) {
System.out.println("Hello, NetBeans World!");
}
- Save your Lab0 project. When
you have finished entering your code, save your Lab0 project (it will be saved within
a directory of the same name, located with the cs102 course directory you created in step 7).
- Within
NetBeans, you have several options to compile and run your program, but
for now the simplest way to do this is to click on the green,
right-pointing triangle button, third button from the right, on the
button bar. Passing the mouse over this button reveals it to be the
"Run Main Project" button.
- If all goes well, you should see the following messages appear in the bottom Output window of the NetBeans IDE:
init:
deps-jar:
compile:
run:
Hello, NetBeans World!
BUILD SUCCESSFUL (total time: 0 seconds)
Notice that clicking the green triangle button causes your program to be saved, compiled and run.
- If
there is a syntax error somewhere in your code, pressing the Run Main
Project button will save it, but the compiler will generate a syntax
error. To see what this looks like, remove the semicolon (;) at the end
of your println() statement and try to compile your program again.
Notice how the Java compiler and NetBeans IDE identify the error
encountered, what was wrong, and what line the error occurred on. Go
ahead and fix the error and recompile once more.
- When your project successfully runs,
alert your lab instructor and follow the submit procedure detailed below.
Submitting your work
From a terminal window, type the
following commands at the Linux prompt:
cd
cd cs102
submit102 Lab0
Log out
When you are done, close NetBeans, and then locate the logout button on the menu bar. Click
on the logout button (red arrow pointing through an open door). Choose
"Logout..." and then click "Yes" when prompted.
Always remember to log out when you are done using the system, to ensure that
no one else uses your account.