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:
-
it can be used with the latest version of Java
-
it's available free of charge -- an advantage not only for our labs but
for students who wish to have a copy at home
-
it was designed for teaching Java at the University level (at Monash University
in Australia)
-
it displays a graphical representation of the classes in your program
-
it has a working debugger
-
it lets you test individual methods without writing test drivers
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 markers will be running your program and they will be using BlueJ.
To be quite safe, if you develop your program with a different tool you
should try running it on BlueJ before you hand it in. I don't know
of any reason why a program developed with, for example, JBuilder 3.5,
shouldn't work with BlueJ, but it's best to check to make sure. The
markers will not have access to the tools you have at home. If your
program doesn't work with BlueJ, you will lose points for correctness.
-
BlueJ is the officially supported Java tool for CISC 124. If you
have trouble with BlueJ, I'm familiar with it and I've got it running in
my office and I can probably help you out. If you choose another
tool, you're on your own.
-
If your home computer should happen to break down, you may find need to
use CASLAB instead. Having to learn BlueJ suddenly right before an
assignment is due may be a rather stressful experience! It might
be good insurance to make sure you know how to use BlueJ even if you plan
to use another tool at home.
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:
-
The most recent version for Windows as of July is at http://www.java.sun.com/j2se/1.3/download-windows.html.
Alternately, start at the main Sun web site (http://www.java.sun.com),
click on "Products and APIs" at the left, then "Java 2 Platform, Standard
Edition", then click on the latest version of the SDK which is not a Beta
version, then on the link for Microsoft Windows (whew!).
-
Once you've found that page, scroll down to where it says "Download Java
2 SDK" and click on "continue".
-
Read the Licence Agreement (or scroll down the page saying "yeah, yeah")
and click "Accept".
-
Click on one of the download sites to download the installer. This
is a very large file and will take a long time if you're using a dial-up
connection (or several minutes with a fast connection). Go get a
cup of coffee or chat with your roommate.
-
Create a new folder to hold your SDK-- I'll refer to this as your SDK installation
folder. Find your installation file (called something like j2sdk-1_3_1-win.exe)
with Windows Explorer or My Computer and double-click on it. The
installation process will take a while. Click on "Next" and "Yes"
when asked, and give the name of your SDK installation folder. At
one point, you will be shown a list of components. If you're short
of space, you can uncheck everything but "Program Files". After the
installation is done, you will be asked to reboot.
-
I highly recommend downloading a copy of the Java documentation.
You can browse it online, but it's much faster to have a local copy.
To get one, go back to the original download page and click on "Browse
and Download Java 2 SDK, v 1.3.1 Documentation". From there, find
"Download JavaTM 2 SDK 1.3.1 Docs - HTML Format" and click on "Continue"
underneath it. Accept the licence policy and you'll get to a download
page. Un-zip it right into your SDK installation folder and it will
create a "docs" sub-folder containing many, many pages of HTML. The
main thing you'll be wanting to use is the API documentation, which will
be rooted at docs\api\index.html. I suggest making a bookmark to
that file.
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:
-
click "Download", on the left side of the screen
-
choose either Windows server and click on the file bluej-114.jar
to download it. (Note: "jar" stands for Java ARchive; it's a compressed
file, kind of like a zip file)
-
create a new folder for BlueJ -- I'll refer to this as your BlueJ installation
folder.
-
Starting up the installer can be slightly tricky, but it's not really difficult.
Try the following steps:
-
Double-click on the jar file from Windows Explorer or My Computer.
If your computer is configured just right to run jar files, this will start
up an InstallShield-like installer. If that works, you're all set.
Otherwise, if you're asked what application to use to open the file, cancel
and go on to the next step.
-
To start the installer from DOS, open a DOS window (Start Menu | Programs
| Command Prompt). Connect to the folder containing the jar file
(for example, if the jar file is in c:\installer, you type "cd c:\installer").
Now type the command: "java -jar bluej-114.jar". If this works, there
will be a pause and then the installer window will pop up. If your
computer complains about an illegal command, your classpaths aren't set
up properly to find the java executable in your SDK. Rather than
fixing your classpaths, go on to the next step.
-
If your system isn't recognizing the "java" command, you'll have to give
it the full path name, which is your SDK installation folder plus "\bin\java".
So, for example, if your SDK installation folder is c:\sdk1.3, you type
the command "c:\sdk1.3\bin\java -jar bluej-114.jar".
-
Once you've got the installer running, the hard part is over with.
Just give it the names of your BlueJ installation folder (that's where
it will unpack all the BlueJ files) and your SDK installation folder (so
BlueJ knows where to find the Java tools it needs to use).
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.
-
To download the BlueJ tutorial from the BlueJ web site, click on "Documentation",
then click on "The BlueJ Tutorial". If you've got your browser set
up to display PDF files directly, you'll see the tutorial. You can
use "Save As" to save yourself a local copy. Otherwise, you'll get
a save dialog right away.
-
There's also a BlueJ Reference Manual available from the Documentation
page. As they warn on the web page, it's a work in progress and some
helpful-sounding sections are not filled in yet, but what's there can be
useful. It may be worth checking back from time to time in case they
write more.
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.
-
Start BlueJ using your shortcut.
-
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.
-
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.
-
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:
public class Hello {
public static void main(String args[]) {
System.out.println("hello, world!");
} // end main
} // end class Hello
-
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.
-
When your class has compiled successfully, close or minimize the editor
window and return to the main BlueJ screen.
-
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.
-
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:
-
You can view or hide the terminal window at any time: in the main BlueJ
window, check or un-check View | Show Terminal.
-
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.
-
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:
-
BlueJ has a nice debugger. An hour or so early in the term learning
how to use the debugger may save you many hours of work later on.
-
BlueJ will let you test individual methods, not just the main method.
This lets you try out a method without the bother of writing a test driver.
This page created by Margaret
Lamb, Queen's University, Kingston, Ontario. Last modified
.