BlueJ is a free Java environment available from http://bluej.org/. 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 http://java.sun.com/j2se/.
BlueJ is a wonderful environment that makes you think about objects and
object-oriented programming. It also contains a simple debugger.
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
bluej
On Linux/Unix, enter a command such as
cd /usr/local/bluej
./bluej
The details depend on your software installation. In some cases, you may be able to click on an icon to launch BlueJ.
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.
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.
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.
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).
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.
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
/home/yourname/homework/or
c:\homework\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.
The output is displayed in a separate terminal window.
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: