BlueJ is a free Java environment available from BlueJ is written in Java and runs on any platform with a Java 2 runtime, such as Linux, Solaris, Windows, or Mac OS X. BlueJ requires a Java 2 runtime, so you need to install the Java SDK first before installing BlueJ. You can download the SDK from

BlueJ is a wonderful environment that makes you think about objects and object-oriented programming. It also contains a simple debugger.

Starting BlueJ

In BlueJ, you should have a subdirectory for each program.

To start BlueJ, open a command shell and type a command such as

cd \bluej

On Linux/Unix, enter a command such as

cd /usr/local/bluej

The details depend on your software installation. In some cases, you may be able to click on an icon to launch BlueJ.

Loading an existing program

If you already have your program in a Java file (or a directory containing multiple Java files), then you need to make a project that contains the file. Follow these steps.

Select Project->Open Non BlueJ from the menu.


In the file dialog, select the directory containing your Java files. Do not select the individual files. For example, the following dialog selects the bank directory.


Click on the Open in BlueJ button.

Now you see the class or classes that BlueJ discovered in the selected subdirectory.


Click the "Compile" button to compile all classes.

Investigating Objects

The biggest difference between BlueJ and traditional development environments is that BlueJ isn't concerned with running programs. Instead, you investigate objects.

Click on a class rectangle with the right mouse button. You see all of its constructors and static methods.


To instantiate an object, select an appropriate constructor. Give the object a name and specify any construction parameters.


NOTE: When supplying string parameters, remember to type in the "..."!

The object is created on the "object workbench" below the class display.

To investigate the object, right-click on it and pick a method.


If the method has parameters, you will get a dialog such as this one:


If the method returns a value, you get a dialog that displays it. For example, here is the result of calling the getBalance method:


Note: With BlueJ, there is no need for a "test" class. You can test your classes simply by creating objects and calling methods.

Investigating Library Classes

With BlueJ, you can investigate library classes just as easily as your own classes. Suppose you want to know more about the StringTokenizerTools->Use Library Class from the menu. Type the name of the class (including the package name).


Then hit the ENTER key. You will see a list of all constructors and static methods of the class.


Select the constructor that you want and click Ok. Fill in any construction parameters. The object is created on the workbench. Right-click on it, and you can invoke any of its methods.


This facility makes it easy and fun to learn more about the library classes.

Starting a new program

If you write a program from scratch, then you can compose your code in BlueJ. You do not need a separate text editor.

It is always best to place each of your programs into a separate directory, such as hw1, hw2, ..., for your homework assignments. You probably want to place all those homework directories into another directory such as

You need to create that directory outside BlueJ, with a file manager or the mkdir command in a command shell window.

Then choose Project->New Project from the menu. In the file dialog, navigate to the parent directory that holds your projects (such as homework). In the name field, enter the name of your project (such as hw1).


You now get a blank project with no classes.


Click on the New Class button. Fill in the name of the class.


Click Ok. You get a striped rectangle for the class. Double-click on the rectangle to bring up an editor window.


The editor window contains a rudimentary (and fairly useless) definition of the class. Clear out the sample instance field and the sample method, and start putting in your code. Click on the Close button when you are done.

To compile a class, click the Compile button.

If there was a compilation error, the editor window is opened. The first error is displayed at the bottom of the screen. Click on the ?
button to get more information about the error.


You need to fix the error and click Compile again until your file compiles without errors.

Running a main method

For many coding examples, you don't need a main method. Simply define classes, instantiate objects, and invoke methods.

However, if you want to run a main method, you can. Simply right-click on the class that defines the main method and choose it from the list of static methods.


Then you get a chance to supply the command-line parameters (that is, the value of args).


For simple examples that don't require command-line parameters, just click on Ok.

The output is displayed in a separate terminal window.


Running applets

To run an applet, right-click on the applet class rectangle and select Run Applet.


A dialog appears that allows you to specify the applet parameters.

You can just leave them at their default settings and click Ok.


BlueJ runs the applet viewer.


Generating Javadoc comments

Simply select Tools->Project Documentation from the menu. BlueJ runs javadoc and places the documentation files into a doc subdirectory. Point your browser to that directory to see the documentation.


Tracing through a program

In the editor window, click on the strip to the left, next to a line in which you would like program execution to stop. You will get a breakpoint, symbolized by a stop sign icon.


Then execute a method (main or any other method). If execution stops at the breakpoint, the debugger window pops up.


Whenever you click the Step button, then the debugger executes one line of the program, without stepping inside method calls. For example, step over the call

Word w = new Word(token);

will not trace inside the Word constructor but simply run the program to the next line of the main method.

Contrast that with the menu option Run->Step Into(or the F5 keyboard shortcut). This command traces inside method calls. For example, tracing into the line

int syllables = w.countSyllables();

stops at the first line of the countSyllables method:


Watching values

The debugger window shows the values of the instance fields of the implicit parameter of the current method (such as text in the example below) as well as the local variables of the currently executingmethod (such as count, end, and ch).


The bottom left window shows the call stack (with the most recently called method on top). For example, this call stack  shows that the WordTest.main method called the Word.countSyllables method.

Stopping the debugger

The debugger stops automatically when your program terminates. Otherwise, simply click the Terminate button on the debugger window.