INTRODUCTION TO BLUEJ

by Edward McDowell

BlueJ is a simple integrated development environment for Java created at MonashUniversity and the University of Southern Denmark for use in teaching elementary computer programming. It is free and easy to use. BlueJ and its documentation may be downloaded from the BlueJ web page The current version of BlueJ requires that the Sun Java Development Kit J2SE 1.3 or higher be installed on your computer. This is available at the Java web page

ENTERING BLUEJ

This introduction assumes that you already have BlueJ installed on your computer. The standard installation creates shortcuts to BlueJ on your desktop and in the "Start:Programs" menu. Use one of these shortcuts to enter BlueJ. (The first time you enter BlueJ you may be asked to specify which version of the Java Development Kit to use with BlueJ. Select a version from the list and click the Launch BlueJ button. If no version of the JDK is listed, click the "Advanced" button and then "Search drives for Java" to search the computer thoroughly for the JDK.)

CREATING A PROJECT

You must create a project for each program that you write. Select "Project:New Project" from the BlueJ menu. A dialog box will open. Enter the name you want for the project folder in the File Name box and click the Create button. (Specify A:\Hello, for example, to create a project named Hello on the floppy disk in drive A.) This displays a project window for the new project. The title bar at the top of the BlueJ window displays the name that you gave to the project. The project window contains one icon (of a page of paper). You may double click this icon to edit a project documentation file. (Click the close button to leave the editor. The edited file will be saved.)

CREATING A CLASS

Click the New Class button to the left of the project window to create a new Java class. A dialog box will open. Enter the name of the class in the Class Name box. Check the appropriate radio button in the Class Type box: the choices are Class, Abstract Class, Interface, and Applet. Class is the correct choice for a standard Java class. Click OK. An icon for the new class will appear in the project window. Double click this icon to edit the class. Click the close button to leave the editor. The edited file will be saved.
COMPILING THE PROJECT

Click the Compile button to the left of the project window to compile every class displayed in the project window. This translates your classes into the Java bytecode needed to run the program. If the compilation is successful, "Compiling... Done" will be displayed in the status line at the bottom of the BlueJ window.

If a class contains an error, an editor window will open and the line where the error was detected will be highlighted. An error message is displayed in a small window under the editor window. Locate and fix the error, close the editor, and compile again.

RUNNING THE PROGRAM

To run an application, right click the icon for the class containing the main method. Select "void main(args)" from the menu. A dialog box will open allowing you to pass strings to the args parameter. Just click OK. The program will run in a terminal window. (EXIT_ON_CLOSE Bug: If you use BlueJ 1.2.2 with recent versions of Java, the program will terminate if you call the JFrame method setDefaultCloseOperation with an argument of JFrame.EXIT_ON_CLOSE. This may be fixed by specifying JFrame.DISPOSE_ON_CLOSE.)

To run an applet, right click the class that extends Applet. Select "Run Applet" from the menu. A dialog box will open. Select "Run Applet in appletviewer". Specify the width and height of the applet in pixels. Click the OK button. The applet will run in the Sun appletviewer. Close the applet- viewer window to exit the applet.

BREAKING A LOOP

Sometimes a program will hang in an infinite loop. To break the loop select "View:Show Debugger" from the BlueJ menu. A debugger window will open. click the Halt button at the lower left corner of the debugger window, click the Terminate button at the lower right corner, and close the debugger window.

CLOSING A PROJECT

Select "Project:Close" from the BlueJ menu to close the current project. Always close the project before removing your diskette or exiting BlueJ. Exit BlueJ with "Project:Quit".

OPENING AN EXISTING PROJECT

It is often necessary to open a project that you started earlier. To open an existing project, select "Project:Open Project" from the BlueJ menu. Enter the name of the project folder, for example A:\Hello, in the File Name box and click the Open button.

J:\Java\EM_IntroToBlueJ.doc<(1)>