CS125 Fall 2008

Lab # 0

Learning the NetBeans IDE

 

The main purpose of this initial laboratory exercise is to acquaint you with 


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
 

  1. 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.
     
  2. Open up a terminal window. Create a new directory named cs125 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 ($): (the first line makes a new subdirectory in your current director and the second line changes the permissions on that subdirectory to hide it from everyone but your account)
     
           $ mkdir cs125
           $ chmod 700 cs125
  3.    
  4. Access NetBeans by typing  netbeans&  at the command line prompt. You could also choose the application by finding its icon, but the command line works just as well. The & is typed after the name of the application to allow you to access other windows while NetBeans is open. If a window appears asking you to register, click the "never register" choice.
       
  5. 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.)
     
  6. 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.
     
  7. A new window will appear with side-by-side menus labeled Categories and Projects.  Under Categories, the Java folder should be highlighted.  Move your mouse to the selection Java Application  under Projects and left-click to select it.  When it is highlighted, left-click on the Next button at the bottom of the window.
     
  8. 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.  
    1. Change the Project Name to lab0.  
    2. Change the Project Location to the cs125 directory you created in step 2. 
    3. The Project Folder name will automatically change to be consistent with the project name you select.  
    4. 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 boxes checked.  The default name used by NetBeans for the class holding the main method is Main.  The package and class name are shown as "package.className" in the text field.  You may change the class name to something else if you want, but leave the package name as is.  
    5. Left-click on the Finish button at the bottom of the window.
       
  9. The main edit window will now appear.  The Projects window will appear at the upper left.  The project lab0 will be open and will list four packages: Source Packages, Test Packages, Libraries, and Test Libraries.  Only the Source Packages will be of interest to us initially.  That folder will be open and will show the package you created and the main class.  The class Main.java will be highlighted.  The Navigation Window below the Projects window allows you to select a class or method name and bring up that class or method in the edit window.  
     
  10. Complete the program. First, type the following information in the header comment:  CMPU Lab 0, the date, and the purpose of the Main.java (to print a greeting to the user). You can type your name in the comment after @author.  This is a Javadoc comment that puts your name in the documentation.  In the edit window for Main.java, replace the comment in the body of the main() method (note that this is not the constructor for class Main) with an appropriate println() statement as shown below. The result should be a main() method that looks something like this: (you should feel free to customize your "Hello, NetBeans World" message :-)

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

    }
     
  11. When you have finished entering your code, save your lab0 project either by choosing the save icons at the top of the window or by choosing "save" from the pull-down File menu. The file will be saved within a directory with the package name, located within the cs125 course directory you created in step 2).
     
  12. 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.
     
  13. If all goes well, you should see something resembling 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.
     
  14. 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 the 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. Notice also that the error is detected to the left of the offending line in the main edit window. Go ahead and fix the error and recompile once more.
     
  15. When your project successfully runs, alert your lab instructor or coach and follow the submit procedure detailed below.

   

Submitting your work

      From a terminal window, type the following commands at the Linux prompt: (the first command changes to your home directory, the second sets control into the cs125 subdirectory, and the third is the command to submit a directory to the cs125 dropbox)

        cd
        cd cs125
        submit125 Lab0

Log out

When you are done, close NetBeans, and then locate the logout button on the bottom menu bar. Click on the logout button that looks like an on/off switch.  Choose "Logout..." and then click "Yes" if prompted.  Always remember to log out when you are done using the system, to ensure that no one else uses your account.