School of Engineering and Applied Science
Department of Computer Science
CSci 190 -- Real Time Computer Systems
http://www.seas.gwu.edu/~csci190
Prof. Michael B. Feldman
mfeldman@gwu.edu

Getting (Back) Up to Speed with Java

One of your programming exercises in this course is a "sort race" in Java. Here is a guide to some materials designed to help you out, in addition to the Java material in Burns & Wellings.

Setting up to use the Jikes compiler

I prefer the open-source Jikes compiler. I think it provides better diagnostic messages and I've written a listing-file generator to produce nice line-numbered listings, with or without interspersed error messages. If you've worked with Sun's Java compiler (otherwise known as javac), I think you'll be pleasantly surprised with Jikes. If you're interested in the overall history and open-source development process of this compiler, visit www.jikes.org.

Using GNAT requires setting up a few path variables and aliases. This is all handled by a shell script, which you invoke by typing
. ~csjava/setup-java
Note the dot and the tilde. If you add this line to the .profile file in your home directory, it's executed automatically every time you log in.

You must also add the following line to the .kshrc file in your home directory:

export CLASSPATH=..:.:/usr/java/jre/lib/rt.jar:/home/projects/csjava/classes

Java compilers and virtual machines are very fussy about the directory locations of source (.java) and output (.class) files, so make sure to copy the above line exactly.

The CSci 190 Java source code distribution

This resides in a zip archive on hobbes, ~csci190/javasource.zip. You can unzip it directly from the archive by typing
unzip -a ~csci190/javasource
This will produce a directory javasource, containing 2 subdirectories:
  • koffman-wolz - some Java threads examples from a textbook that is now out of print
  • csci190 - Feldman's examples

Using Jikes on hobbes with the CSci 190 programs

We assume that you've run the setup script, and unzipped the source programs.

The setup gives you a locally-written simple script, jcompile, that allows you to compile one or more source files at a time. The advantages of this script are:

  • you know exactly what you're compiling
  • you get a listing (.lis) file with interspersed error messages
Java compilers act as though they have a built-in make facility. Give it the name of a file, and it will look for all the .class files this one needs. If it finds no .class file, but does find the corresponding source file, it will compile that source file "silently". (If you use the compiler's -verbose option, you'll get more information). It's better, therefore, to compile the files yourself, because then you can get listing files.

Try moving in your directory to javasource/csci190, list the directory so you know what's there, and use the Sun compiler to compile something:

javac -verbose ShowThreads.java

List the directory again, and you'll see the .class files that were generated. Now run the program:

java -verbose ShowThreads

Notice how many system classes a simple program uses!

Now you can compile a single program with jcompile:

jcompile ShowThreads.java

and notice that you now have ShowThreads.lis, your listing file. Examine it with an editor, or cat. You can get .class files and listings for everything by typing

jcompile *.java

Both compilers produce compatible output for the JVM, so you can freely intermix javac and Jikes compilations. In either case, you run a program by typing java.

You might try deliberately putting a syntax or semantic error in one of the files and observe the diagnostic information from the two compilers.

Working on your own computer

If you have a Windows or Linux PC and wish to install Jikes on it, you can download from the "official" public distribution site linked from www.jikes.com. There's no Mac binary there, but the sources are compatible with OS X, so if you know how to build GNU packages you can easily download the source and build the compiler. On my PowerBook G3 it built the first time.

A great Windows, Linux, and Mac (OS X) editor is jGRASP, which you can download from its home site at
http://www.eng.auburn.edu/grasp/

This editor is "smart" and "understands" the syntax of many languages, including both Ada 95 and Java.