CS 170 Lesson D logo
 
Introducing BlueJ

BlueJ is an interactive Java development environment, designed specifically to teach programming. There are several things that make BlueJ unique as development environment:

    The BlueJ IDE logo.
  • BlueJ is written in Java, so it works the same on Unix, on Mac OS X and on Windows, (unlike JCreator, which only works on Windows).

  •  
  • BlueJ integrates an editor, a compiler, a debugger, and an interactive console window where you can "test out" small snippets of Java code before you put them in a program.

  •  
  • BlueJ allows you to create and interactively manipulate, inspect and modify individual objects. No other IDE allows you to do this. Only BlueJ allows you to concentrate on objects, rather than concentrating on writing programs.

Even if you use another IDE for most of your programming, you should download and install BlueJ just to try out its interactive programming facilities. Fortunately, BlueJ is both free, and pretty small (about 3 MB).

Here are the steps you need to follow to download and configure BlueJ on your own computer. Read through these abbreviated instructions first, and then walk through the step-by-step instructions. (Before you download and install BlueJ, make sure you have downloaded and installed the SDK. You don't need the Java documentation before using BlueJ).

  1. Download BlueJ. Go to http://www.bluej.org/download/download.html , download and save the version of the installation program designed for your platform.
  2. Install the Program. On Windows, you should double-click bluejsetup-204.exe. On the Mac, simply download to the desktop, and copy the program to your Applications folder.
  3. Configure BlueJ. Hook up the SDK the first time you run BlueJ.
  4. Test your Installation. Run one of the sample programs that come with BlueJ to make sure everything is working correctly.

Following are step-by-step instructions, with pictures, no less!

Step 1: Download and Save

Point your browser toward

http://www.bluej.org/download/download.html

On the download page, click the link for the program appropiate for your platform. Make sure, also, that you've installed either a 1.4.2 or a 5.0 version of the JDK. You can read more about the exact requirements in the sidebar that appears on the right of the download page.
Selecting a download link.
Save the file you download in a temporary directory, or on your desktop.

Step 2: Install the Program

If you're installing on Windows, locate the file bluejsetup.exe, and double-click it to start the setup process.
Running the BlueJ installer.
The BlueJ Setup Wizard, which is a standard Windows installation program, which will guide you through the steps necessary to get BlueJ installed on your machine.

I usually accept the default options for each of the installation screens, except for the installation location; instead of installing in C:\Program Files\BlueJ, the installer wants to put the program in C:\BlueJ, which is kind of unusual. You can click the Browse button on the Select Destination Location screen to indicate a specific location:
Specifying an alternate installation location.

Once the program is installed, click the Finish button to launch BlueJ for the first time, so you can configure and test it. You can also display the "Read Me" file, if you like:
The BlueJ Setup confirmation screen.

Step 3: Configure BlueJ

BlueJ doesn't have as many options as JCreator, (or, at least, it has different kinds of options). The only thing you really have to configure is to tell the program which Java Virtual Machine to use.

Since BlueJ requires J2SE 1.4.2 or J2SE 1.5, it's unlikely that you'll have more than one SDK version available. When you start the program for the first time, (by clicking the icon on your desktop), you'll see a screen that looks like this:
The BlueJ JVM selection screen.
Choose the JVM you want to use, (if more than one appears), and you won't see the screen again. If you want to change JVMs later, (when you install J2SE 5.0, for instance), you can run the Select JVM program again from the Start Menu.

Other Configuration

Most of the "day to day" options are available on BlueJ's Preferences dialog, available from the Tools menu. I, for instance, always turn on the line number display, as shown here:
The BlueJ preferences dialog.
The more advanced settings, however, are controlled by a configuration file named bluej.defs, located in the lib folder inside the directory where you installed BlueJ.

If you are using the Mac, you won't find a lib folder. Instead, you need to Ctrl+Click the BlueJ icon, and then choose Show Package Contents from the context menu. when the Finder "opens up" the BlueJ package, you'll find the BlueJ.defs file in the Resources/Java folder. You can edit it using TextEdit or any other editor.

Use Notepad, SciTE, or another text editor to browse through the file. There are comments telling you what each of the options do. If a line begins with a "hash mark" (#), then the line is disabled or "commented out".

One of the things you might want to change is the location of the JavaDoc help files. BlueJ comes configured to use the online J2SE 5.0 help files. If you are using J2SE 1.4.2, you might want to change that by putting a # in front of the line that refers to the 5.0 version, and adding another line that refers to 1.4.2, as I've done here:
Modifying the blueJ.defs file.

The BlueJ Web site has an extensive list of configuration topics in their Tip of the Week archive.

Step 4: Test your Installation

BlueJ, as I mentioned earlier, is really different from JCreator or Eclipse. BlueJ is object-focused, instead of program-focused. Because of that, rather than simply creating a "Hello World" application, let's test BlueJ by opening one of the example programs that were installed along with BlueJ.

Open the Project

Choose Project->Open Project from the main menu, or press Ctrl+O:
Opening an existing project
Navigate to the folder where you installed BlueJ, and then open the Examples folder. Inside this folder you'll see a bunch of small brown "L-shaped" icons that represent BlueJ projects. (If you look at the same folder using Windows Explorer, instead of BlueJ, you'll see that they are regular folders containing the BlueJ project information. I believe the brown "Ls" are supposed to be a stack of "packages", but I'm not sure.)

Locate the shapes project, select it, and click the Open button:
Selecting the shapes project.
When you click Open, you'll see a graphical representation of the project that looks like this:
The shapes project when first opened.
Each of the classes in the project is represented by a tan rectangle, with a name along the top. The diagonal gray stripes appearing on each class indicate that the class has not yet been compiled. The arrows going between classes indicate the class relationships used in the program.

You'll learn about classes, objects, and class relationships as the semester goes on. For right now, though, let's just learn how to open the source code files, compile the files, and then "run" the results: pretty much the same things we did with SciTE and JCreator.

The Source Code

To open the editor part of BlueJ, just double-click one of the class files, (or the "Read Me" file appearing in the upper-left corner. Here, for instance, is what the editor looks like when I double-click the Circle class:
Opening the Circle source code file.
Whenever you open a file in BlueJ, it opens up in its own independent editor window that you can move around the screen and position as you like.

As you make changes to your file, you can save it, and compile it separately from the other classes in your project using the editor window menu or the buttons on the toolbar. When you close an editor window, your changes will automatically be saved, but the class won't be compiled.

Compile the Code

Remember, you turn a Java program into executable bytecode by compiling it. In BlueJ, you can compile an individual file from the editor window, or by right-clicking on its icon, and choosing Compile. You can also compile all of the classes in the project by clicking the Compile button, shown here:
Compiling the Shapes project.
Once you've compiled the project, all of the diagonal grey lines disappear from the class diagram.

If a problem occurs when compiling one of your files, an error message will be displayed, and an editor window will automatically open up containing the offending line of code so you can correct it.

Let's see how that works. Double-click the Circle class again, (or choose the Circle class editor window if you hadn't previously closed it.) Remove the semicolon at the end of the first line of code, and click on the Close button to save the file:
Introducing an error into the Circle file.

Notice that when you return to the BlueJ project window, the Circle class now appears "striped" to show that it needs to be compiled. Click the Compile button to compile any uncompiled classes, (only Circle in this case). When you click Compile, the editor window pops up with the Circle class loaded:
The BlueJ editor with an error displayed.
The editor highlights the line where the error was encountered, and prints the error message, (; expected), in the status area at the bottom. If you click the question-mark icon appearing to the right of the status area, BlueJ will give you a little more help, as shown here:
Help on a syntax error in BlueJ.

In any event, just like any other IDE, BlueJ requires you to correct your error, using the editor, and then compile again. Continue the edit-compile cycle until all of the files compile without any syntax errors.

Creating Objects

Instead of "running" your program in BlueJ, you create objects, and send messages to those objects. This is quite different from other Java development environments.

Let's see how that works by creating a Circle object, and then manipulating the object. Right-click the Circle class, and choose new Circle() from the context menu. (You'll learn more about what this means in upcoming lessons.)
Creating a new Circle object.
BlueJ asks you to supply a name for your object, and offers the suggestion circle1:
Naming your new Circle object.
That's fine for now. Just click OK and BlueJ creates a new instance of the Circle class with the name circle1. (We normally call an instance of a class, an object). It places the newly created object on the Object Bench running along the bottom of the IDE: The circle1 object.

Sending Messages

Once you've created a Java object, what can you do with it? Good question. Using BlueJ, you can do two things:

  1. You can inspect the object to examine the contents of its data fields. (This is called the object's state.)
  2. You can send messages to the object, telling it to perform any of the actions it knows how to do.

Now normally, in a Java program, you'd do these things by writing code. In BlueJ, you can do them interactively.

Inspecting

Right-click the circle1 object on the Object Bench. From the context menu, choose Inspect. This launches the Object Inspector dialog that allows you to "peer inside" the circle1 object:
Inspecting the data fields inside the circle1 object.
As you can see, this object has five pieces of data associated with it: three numbers, representing its diameter and its position on the screen, one text value representing its color, and one true/false value indicating that circle1 is not currently visible on the screen.

If you try to change one of these values, setting isVisible to true, for instance, you'll see that they appear to be "read only". That's one of the main principles of object-oriented programming: the data inside an object is private, and can't be directly changed by an outside agent, (that is, by you).

So, how do you change the data contained in an object? You "ask politely" by sending the object a message.

Sending Messages

Let's make our circle1 object visible on the screen, so we can see the changes that occur when we modify it. To do that, right click the object on the Object Bench, and locate the entry that says void makeVisible():
Making the circle1 object visible.
This group of entries that begin with the word void, and that end with parentheses, are the methods that the object contains. By "calling a method" you tell the object to carry out some action, in this case, to make itself visible.

The Shapes Demo program. When you send the makeVisible() message to the circle1 object, it opens the BlueJ Shapes Demo program, and displays the circle on the screen.

If you inspect circle1 after doing this, you'll see that it's isVisible field has changed from false to true.

Next Steps

Go ahead and experiment with sending some other messages to the circle1 object. Try to change its size, its color, and its position. Then, add another object, maybe a triangle or a square, and make it visible as well.

To learn more about how to use BlueJ, open the BlueJ Tutorial from the Help menu. You can also open the reference manual and the online Java help from the same menu.