header

Using BlueJ

In this lab exercise, you will create your first Java program. I'll warn you ahead of time, that it won't really do much but you will begin to learn how to use the BlueJ integrated development environment to write a program.

1. Create a new folder in your user space (on network drive U:) named "JavaProjects". All of your Java projects will go in this folder.

2. Run BlueJ.

If you installed BlueJ on your personal computer, you can double-click the BlueJ icon on your desktop or use the start menu: Start, Programs, BlueJ, BlueJ.

It may take some time for BlueJ to initialize itself so be patient.

3. Create a new project by selecting the New Project... option from the Project menu:

Sometimes BlueJ can take quite a while to display the New Project window, so be patient.

4. When the New Project dialog opens make sure the Look In: folder is your JavaProjects folder. Then type in "Lab01" in the File Name: text box, and click the Create button:

Create New Project Named "Lab01" 

BlueJ creates the folder for your project and creates a text file in which you can place information about the project. This text file is represented by an icon that looks like a sheet of paper. (We will not be using this file in our projects.)

5. Click the New Class button in the project window.

Click New Class Button

6. In the Create New Class dialog, type in "Lab01" as the class name, select the BlankApplication radio button, and then click the OK button.

Create a New Class Named "Lab01" 

Believe it or not, you have created your first Java program. It doesn't do anything yet but nevertheless it is an executable program. The gray stripes through the program icon in the project window indicate that it needs to be compiled:

You've Created Your First Java Program 

7. Click the Compile button on the project window. In the lower-left corner of the project window, you'll see the message "Compiling...". When the compiler is done, the text will change to "Compiling... Done". Notice also that the gray stripes running through the program icon have been removed.

8. Double-click on the program icon to open it in the BlueJ text editor. Edit the first documentation comment to include a description of the program, your name, and the current month and year similar to this:

/**
 * Lab01 displays the message, "This is my first Java program."
 *
 * @author D. Searls
 * @version 08/2010
 */ 

9. Click the Compile button (at the left, near the top) on the text editor window to make sure that you have not introduced any errors. In the lower left corner you will see the message "File Saved" shortly followed by "Class compiled - no syntax errors". If you introduced syntax errors, correct them before continuing.

10. Click the Close button on the text editor to close the text editor window. Back on the project window, click the Tools menu and select the Project Documentation option:

Java Project Documentation Tool

This tool generates the Java documentation for this project and displays it in a web browser. (If your browser is already open, the documentation should be displayed in a new tab.) Don't worry about the fact that you don't understand most of what you see. If you look through the documentation, you will see that the information you included in the documentation comments in your program show up in the java documentation of your project.

The first time you use this documentation tool, BlueJ will just generate the documentation and show it to you. If you use this tool again after the documentation has already been generated, the dialog shown below will appear. If you've made no changes in your documentation comments, you can click the Just Show button. Otherwise, Regenerate the documentation to include any recent changes.

11. Double-click on the program icon again to open it in the BlueJ text editor. Edit the method named "main" as shown here:

    /**
     * Main driver begins program execution.
     *
     * @param args program arguments
     */
    public static void main(String[] args) throws Exception
    {
        System.out.println("This is my first Java program.");
    }

12. Compile your program and, if necessary, correct any syntax errors.

13. Close the editor window.

14. In the project window, right-click on the program icon and select the option "void main String[] args". This will cause your program to be executed within the BlueJ environment.

Run the Program 

When the method call dialog window appears, just click the OK button:

Click OK in the Method Call Dialog

A terminal window will appear with the text "This is my first Java program". You can close this window by clicking the close button at the upper right:

The Java Terminal Window 

15. Open the Project menu and choose the Close option to close your first programming project.

16. Open the Project menu and choose the Quit option to terminate the BlueJ program.

Submitting Your Work

Send me your Lab01.java application as an attachment to an email message. Enter "Lab01" as the subject of the message. You can leave the actual message blank.