Queen's Logo

CISC 124: Introduction to Computing Science II

(Fall 2001)

BlueJ Information

[Home] [Schedule & Readings] [Exams & Grading] [Assignments] [Slides & Examples] [FAQ] [Announcements] [Resources] [Java] [BlueJ]

Why BlueJ?
Do I Have To Use BlueJ For My Assignments?
Installing BlueJ at Home
BlueJ Documentation
Starting BlueJ
A Quick Start to Using BlueJ

Why BlueJ?
Most of you have taken other CISC courses at Queens and used either JBuilder 2 or Ready To Program.  You may be wondering why you are being asked to learn to use a different Java tool for this course.  The reason is that both of these tools use Java 1.1.  This version is adequate for CISC 101 and 121, but there were huge changes to the Java libraries (API) between version 1.1 and 1.2.  Since one of the main emphasis of CISC 124 is the use of Java libraries, it is important that you have an opportunity to learn with a more current version.

No, BlueJ is not perfect.  (If you know of a perfect Java tool, please let me know -- we're all looking for one!)  I chose BlueJ for this course because:

Do I Have To Use BlueJ For My Assignments?
If you do your assignments in CASLAB, the only tool available to you with the recent Java libraries is BlueJ, so that's what you'll have to use.  If you choose to do your work on your home computer, you may use any Java tool you wish as long as it runs Java 1.2 or higher.  However, I have a few cautions for you if you chose to use a different tool for your assignments: The CD that comes with the textbook includes JBuilder 3.5, which does include the Java 1.2 libraries.  There are both financial and technical reasons we can't install this version of JBuilder in CASLAB, but you can try using it at home.  If you want to use JBuilder at home, you might want to consider downloading JBuilder 5 from Borland instead; the personal (non-commercial) version is free.

By the time the fall term starts, it may be possible for you to download a copy of Ready to Program which uses Java 1.3 -- and the lab versions may have been upgraded to use Java 1.3.  (As I'm writing this page late in August, it's still not clear what will be available for the fall term.)  There are many, many other Java tools available on the web which you can try out, or you can learn how to use the SDK directly with DOS.

Just remember that the focus of CISC 124 is on the Java language and API, not the tools.  I will help you with BlueJ, and I may be able to answer simple JBuilder questions, but that's all.

Installing BlueJ at Home
(Warning: These instructions are for Windows.  There is a version of BlueJ for MacIntoshes also, but you'll have to figure it out on your own.  I don't have access to a Mac, so I can't try it out.)
BlueJ is an interactive tool that uses Sun's Java compiler and interpreter.  The BlueJ installation file does not include these programs.  So before you install BlueJ, you must install Java itself.  What you need is the Java SDK (Software Development Kit).  (If you've heard people talking about a JDK, this is an old term for the same thing.)  If you already have a Java SDK, version 1.2 or higher, you can skip this first step.

Note: If you have JBuilder 3 or higher at home, it includes a Java SDK.  Look at the folder in which you have installed your JBuilder.  There should be a sub-folder called jdk1.2.2 (or another set of numbers, 1.2 or higher).  You can skip the next section and use this sub-folder as your SDK installation folder.

To install an SDK: Visit the Sun web site (http://www.java.sun.com) and follow the links and instructions to download and install the most recent SDK, which as of July is 1.3.1.  (I don't recommend trying a Beta version.)  If you want more detailed instructions, here they are:

Installing BlueJ: Once you've got an SDK, you can install BlueJ itself.  Go to http://bluej.monash.edu.  The download and installation procedure isn't too hard, but here are detailed steps: BlueJ Documentation: Unfortunately, BlueJ doesn't have the normal help menu stuff we're all used to.  It does have a tutorial in PDF format.  (If you don't have a PDF reader, you can get a free one from http://www.adobe.com.)   It's a pretty good tutorial, but not well organized for getting started quickly.  You can get a quick start from the "quick start" section of this web page, but eventually you will probably want to read the tutorial. Starting Up BlueJ: To run BlueJ, double-click on the file bluej.bat in your BlueJ installation folder.  This creates a large DOS window, then starts up a small BlueJ window.  If the large DOS window irritates you as much as it irritates me, you can hide it.  Create a shortcut to bluej.bat (from Windows Explorer, right-click on the file and choose Create Shortcut).  Right-click on the shortcut and choose Properties, then click on the Shortcut tab.  After "Run", choose "Minimized".  You can copy this shortcut to your desktop and/or start menu.  When you run BlueJ with this shortcut, you won't see the DOS window (although it will still show up on the task bar).

A Space-Saving Suggestion: Once you've verified that BlueJ runs correctly, you can save disk space by deleting or backing up both the BlueJ and the SDK installation files.

A Quick Start to Using BlueJ: This section will walk you through writing and running a simple Java program with BlueJ.  Before you start, you need to understand how BlueJ views projects.  You are probably used to the concept of a project if you've used JBuilder.  With BlueJ, you can't edit, compile or run a file unless it's in a project.  If a program consists of several Java files, they must be grouped together in the same project.  BlueJ creates a folder for each project.  (It's difficult to create a project in an existing folder -- let BlueJ create the folder for you.)  As you create, compile and run the project, you will notice that BlueJ creates files in that folder.  You should leave these files alone.

  1. Start BlueJ using your shortcut.
  2. Create a new project: from the Project menu, by choosing New Project.  You'll get a file open dialog; this will create the folder where your project will live.  The main BlueJ window always shows you the files in your project.  Right now, there will be only one file showing.  If you double-click on it, you will see that it is a README.TXT file, in which you can record information about the project if you wish.  Use the Close button to get rid of that window.
  3. Create a Java file for your program from the main BlueJ window by clicking the New Class button.  You'll be asked for a name; this will be the name of your Java class.  For example, if you want to create a class called Hello, type in "Hello".  BlueJ will create a file called Hello.java.  Under "class type", leave "class" selected.  Now you'll see another file in the main BlueJ window.  It will have diagonal lines across it, showing that the file has not been compiled.
  4. To edit your Java file, double-click its box in the main BlueJ window.  This will create an editor window for your file and you'll see a little template BlueJ created.  Get rid of that (control-A and then Delete does it quickly) and then type in a simple Java class.  For example, you could copy the following:
    1. public class Hello {
       public static void main(String args[]) {
         System.out.println("hello, world!");
       } // end main
      } // end class Hello
  5. When you have finished writing your class, you can type control-S to save it, then push the Compile button (or type control-K) to compile it.  You'll get a message on the bottom of your screen indicating whether the compilation was successful.
  6. When your class has compiled successfully, close or minimize the editor window and return to the main BlueJ screen.
  7. At this point, you may be looking for a "run" button, but there isn't one.  Instead, right-click on the icon for your Java file.  There will be an entry for every constructor and static method in your class.  This can be very useful for testing, but for now just pick the main method.  A method-call window will pop up; click OK.  This will run your main method.  A terminal window will pop up and show you the output from your program.
  8. Run your program a second time.  You'll see that the output from that run will be appended to the output from the first.  Ths can be a useful feature, but it's often just annoying.
More about the terminal window:
  1. You can view or hide the terminal window at any time: in the main BlueJ window, check or un-check View | Show Terminal.
  2. Even if you hide or close the terminal window, the output from all your runs will remain in the window.  If you don't like this effect, you can clear all output from the window: from the terminal window, choose Options | Clear.
  3. If you want to save the output of a program (for handing in an assignment, for example), clear the window and choose Options | Unlimited Buffering.  Then run your program, and choose Options | Save To File, and your ouput will be copied into a text file.  (If you want the .txt extension, remember to specify it when you give the file name.)  Alternately, you can use the normal Windows keyboard commands (control-C and control-V)  to copy output from the window and paste it into another document.
Importing a file:  Suppose you want to use an existing file as part of your program.  For example, suppose you want to modify the Hello program to take input using the SavitchIn class, as follows:
public class Hello {
  public static void main(String args[]) {
    System.out.print("what is your name? ");
    String yourName = SavitchIn.readLine();
    System.out.println("hello, " + yourName + "!");
  } // end main
} // end class Hello
You'll have to put a copy of the SavitchIn class into your project.  From the main BlueJ window, choose Edit | Add Class From File.  Browse to your copy of SavitchIn.java.  (You can get one from the CD that came with your textbook, under the examples for Chapter 1, or here.)  BlueJ will make a copy of this file and put it into your project folder.  You could open this file with the editor, but it's easier just to click Compile in the main window.  This compiles every file in the project that needs to be compiled (i.e. it has been modified since the last time it was successfully compiled).

Now you've seen how to create, compile, and run a program with more than one class.  That's enough to get by with.  BlueJ has other very useful features, which are worth learning about from the tutorial.  Two items of special interest:

This page created by Margaret Lamb, Queen's University, Kingston, Ontario.  Last modified  .