Using NetBeans 6.7.1 to Create and Run a Java Application

(Updated 29 Dec 2009)

NetBeans is an open source IDE (integrated development environment) available to programmers who want to develop Java projects. Since it is an IDE, the tools needed for editing, compiling, building, debugging, executing, and obtaining online help are all integrated in one graphical user interface. Using these tools effectively can greatly increase your productivity.

Please see the link on my web page to download the latest version of NetBeans 6.7.1 bundled with the latest Java, Java 6. You must download these and install them prior to running this tutorial.

1.  Start NetBeans by selecting NetBeans IDE 6.7 from the Start menu or by double-clicking the desktop shortcut (recommended). If you get a registration box option, you may register, if you like (I did). But then you should see a screen that looks like this:

2. There is a lot of useful information on these links. To get rid of the Start Page, click on the X as shown via arrow.

You will see the following screen.

3. You will want at least a files pane and a projects pan. You may select these by clicking on them in the drop down box under Window in the menu bar. This will give you a screen that looks like this:

4. Most activities in NetBeans are considered ‘projects,’ as all your programming efforts will end up being projects.

5. Under the File menu, select New Project. You will see this New Project Window in the middle of the NetBeans 6.7 Window

Before starting, you should create a folder on your desktop entitled COP2551. Each lab project this semester will be entitled, projectiyouruserid, where i is the number of the project. For example, your first project would be entitled: project1jsmith. Project1 should be a subfolder within your COP2551 folder. Each project you develop will be located in a different subfolder within COP2551, such as project2jsmith, etc.

To continue working on a project that was begun earlier (you will see a list as you develop projects) , simple click on the desired project in the Project window and continue development. You must also ensure that the project you are working on is the Main Project, and there can be only one Main project (more later on this).

6. New Application: To create and run a new Java application you must first create a project. In the following exercise we will be creating a project named projectiyouruserid.

Now, select JavaApplication from the New Project window, and then click the Next button below. (If you wanted to develop Applets, you would select Java Class Library)

(Also: select some of the other options and note the Descriptions below.)

You will need to make a few changes to the New Java Application Window that will appear: You will need to change entries in Project Name, Project Location, and Project Folder:

Here are the changes I made. You will tailor yours to your own name, etc. Please be careful here.

In the Project Name box, I typed project0broggio. As you type in your own project0jsmith, please note that as you type, the text box midway down on the page inserts this Project Name in front of Main. (This is desirable and we will discuss later).

I then modified the Project Location text (the Project Folder textbox is filled in automatically for you from the Project Location text). You need to enter appropriate settings for your project now too.

You will need to retain your n-number. You can see that I have everything on my desktop via the Desktop, and then the folder COP2551. When you installed NetBeans 6.7, it ‘got’ my n-number. But I changed the default entries that follow to Desktop, and then the folder COP2551, as discussed.

Mine now appears as:

Click the Finish button.

Now, we’ve got our project set up to really start to program! Here is what you should see (using your name, of course)

You will see:

Note all the information that is already supplied for you.

Please take a few moments to look these over.

Note the content of the files pane. Note that your project name and the name of your ‘main’ module is already established! Note the skeletal code that is already provided for you. This will help to get you started, but you will need to understand what is actually being provided for you, since not all IDEs provide the same help.

In the Projects Pane, you may plan with the + and – boxes and see the expansions…

Note: You may wish to take time out and access your COP2551 folder on your desktop. You will note that a subfolder entitled projectiyouruserid will appear.

At this time, you are ready to use the IDE to develop your Java application. I am providing the code for this one (project0) in order to familiarize you with the IDE a little bit and the use of Digital Dropbox for submitting your projects to me.

Please note that I use things call scope terminators and rather rigid indentation conventions, which I feel all competent designers and programmers should use.

There is more information on these Standards and Conventions on my web page.

7. Building the Source Code and Executing it.

The purpose of project0 is to familiarize the student with the procedure in using NetBeans IDE and submitting a job to the instructor in proper format for grading. The value of project0 is twenty points and you should get the entire 20 points if you follow the procedure outlined below.

Note: This is the time to play with NetBeans to not only submit the required project assignment, but to experiment and play around with the very powerful IDE. The on-line tutorial that comes with your CD is excellent. Take time to learn a few other neat things. Perhaps you may wish to develop an applet or two.

As mentioned, your first Java program is provided below.

Here’s the code you are to carefully enter into NetBeans, compile and execute:

Note: some of these lines are already provided. Enter the lines not present on IDE:

/*

* Main.java

*

* Created on July 13, 2009, 12:00pm

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

package project0whooper; // enter your project, such as project0jsmith;

/**

*

* @author n00010109 // provided by the IDE

*/

public class Main { // add code starting at arrow:

// Be certain to indent!

/** Creates a new instance of Main */

public Main() {

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

int sides = 7; //declaration with initialization

System.out.println ("A heptagon has " + sides + " sides.");

sides = 10;

System.out.println ("A decagon has " + sides + " sides.");

sides = 12;

System.out.println ("A dodecagon has " + sides + " sides.");

}// end main()

}// end class

My screen looks like:

Note the very nice coloring: Yellow provides scope bounds; orange indicates string text, blue indicates key words with special means, and more. These are VERY useful!

To compile and run this application, I clicked on the green arrow up in the menu bar.

The output appeared in the Outbox pane. The green arrow requests both compilation and execution of the code. You may alternatively use the Menu Bar, Build, Build Main

Project followed by Menu Bar, Run, Run Main Project. You should see:

Some quick tips:

1. I went to the View menu and selected Show Line Numbers.

2. then I went in and mistyped printline on line 25. NetBeans will often let you know when you are keying in something it does not recognize even before you attempt to compile / run your program. You can see from the screen below, that as I typed prntln, NetBeans flagged it immediately. Now, if I persisted and didn’t note that and then tried to run the project, I would get the output indicated below:

Note that the diagnostic indicates the line number where the error was detected. (If you ‘mouse over’ the red ball, the diagnostic text is provided) You will now need to go back in with your mouse and correct the typo and rerun to get the proper result, which I indicated in the previous slide.

8. Submitting the project for grading.

Go to your desktop and open COP2551. If you double click on the project folder, you will note that there are a number of folders – the same that is reflected in the IDE windows. You might find them instructive to open them and ‘look around.’

Zip contents of the folder, project0broggio.

(Right click, Send compressed file To Compressed Folder) The zipped (compressed icon) should now appear in your COP2551 folder.

You should see

9. Using Blackboard Assignment Link to get Your Assignment (Project)

Access Blackboard using your n-number and your password.

Go to Course Documents in Blackboard. (Alternatively, you may access my web page at www.unf.edu/~broggio and select the golden ball next to your course number. All assignments and help / input files will be available there. ) You will see the assignment and all associated files. If you have any questions, please email me immediately.

Upon completion of your assignments, you must access this Assignment Tab. This is the only mechanism for me to receive your assignments. So please be careful.

Within the specific assignment link, you are afforded the opportunity to send me a zip file of your work. This zip file should be entitled projectnyouruserid, as in project3broggio as mentioned previously. This zip file should be located on your desktop in a folder entitled COP2551 or COP3540 or relevant course number. Be certain the project folder is zipped. If you are not familiar with ‘zip’ then please ask.

‘rar’ files are NOT accepted. If using a MAC, there are special considerations.

Browse your desktop to identify this zipped folder; Attach the zip file using the appropriate button to your screen. After you have attached the file, you must then Submit the attachment. You will get some information back as to the file size, date, time, etc. Please hold on to this until I confirm that I have received your zip file and have successfully unzipped it.

File Information (again):

Log into Blackboard to access initially and submit your completed assignment.

Browse your desktop to your COP2551 folder; select your zipped project

file, such as project0jsmith or whathaveyou (the one with the zipper on it)

Attach the zip file.

Submit.

In the past, we have had a few difficulties here. If for some reason your zip file is not received or arrives to me ‘empty,’ and if you have the date/time that you submitted it, I can have you resubmit with no penalty.

To provide yourself with evidence that you have successfully submitted the project, I recommend that you go back into the Assignment on Blackboard (after uploading to me) and download it back to your computer from the server and unzip it. You will see what you sent to me. Below is what you will see when clicking on the assignment in Blackboard again after submitting your file. As you can see in the second half of the page (you may need to zoom), there is a link with the file you submitted. By clicking on this, you will download the file that was submitted to be for grading. You may then unzip this and verify the presence (or absence) of files.

PLEASE ensure you sent to me what you ‘think’ you sent to me. (See above)

If you send me the wrong folder, I cannot grade it and you will be hating everyone including me. Double check your work, please.