General Lab Information


[Homepage] | [General Lab Info] | [TA's & Tutors] | [FAQ's] | [Supplements] | [Homework] | [Excellent Programs] | [Exams]

Note: For lab times goto [TA's & Tutors] page.

Editing a Program

You can use your favorite text editor for your Java programs. The source file should end in the extension .java.

Using tio in the labs

You can use teach.ic.ucsc.edu, learn.ic.ucsc.edu, hawkings.ic.ucsc.edu, or curie.ic.ucsc.edu for programs in this class (in addition to the workstations in BE105). To automatically include tio you will need to also set your CLASSPATH. The simplest thing to do is create a file .gpue_path (don't miss that dot at the start of that file name) and put the following line in the file:
setenv CLASSPATH .:/afs/cats.ucsc.edu/users/s/mcdowell/java/public
Don't miss the first two characters of the path which are dot colon. Make sure there is a newline at the end of the line. Put the file in your home directory. The first time you will need to log out and back in, or just type:
source .gpue_path

Compiling a Program

The command to compile a Java program is ``javac''. If you had a program called Hello.java, you could compile it using the command ``javac Hello.java''.

Running a Program

After you have "compiled" your program, you run it using the Java Virtual Machine which is called simply, "java".
For example, if I compiled my ``Hello.java'' program using the command ``javac Hello.java'', I would type ``java Hello'' at the UNIX prompt to run my program. Notice that it is not "java Hello.java" or "java Hello.class".

Sometimes it is important to have a copy of your program or its output on paper. Either because it's easier to take your program home this way, or simply because the TA or Instructor want you to do so. In a UNIX environment, you'll need to use the ``lpr'' command for that. But you need to ask the lab consultant what is the printer closest to the lab you're working at. If you want to print a program called ``MyProgram.java'', the command to be used is ``lpr -h -P <printer_name> MyProgram.java'' where
Your file is placed in a queue of files to be printed. Please, bring your printer card... The university charges you a small amount for each page printed.

Debugging Programs

If, when you run javac, you get a whole slew of compiler error messages, work on fixing the first couple of errors and then re-compile; the later error messages probably result from javac getting confused after the first error.

If you are on a terminal that doesn't let you scroll back to see the first errors, you can redirect the error messages to a file by using >&. To name the error file errs, type ``javac Prog.java >& errs''; use ``head errs'' to see the first ten lines of that file or ``more errs'' to scroll through the file.

If things are getting really tough, you can use a debugger. All Integrated Development Enviroments (IDEs) have built in debuggers that are very nice. For beginning students, the overhead of figuring out an IDE can be more trouble than it is worth. There is a simple debugger that comes with the standard Java Development Kit (JDK), which we are using. It is called jdb.

If your program is throwing an exception and the message gives you a stack trace but it says "compiled code" instead of showing you the line numbers of where you were in your program, trying running your program with the command:

    java -Djava.compiler=NONE YourClassFile

Using jdb

To start debugging your program first compile it with "javac -g MyProg.java". Notice the "-g" flag. This causes the compiler to insert debugging information. Then type


    jdb MyProg
    stop in MyProg:main
    run
    list
This should show you the first few lines of your program, with an arrow pointing at the first executable statement in main(). Type help to get a complete list of debugger commands. Here are a few.

Running eXceed in BE213

You can get x-terminals (like working in BE105) by the following:
  1. Click Start
  2. Click X-Windows
  3. Click X-term on hawking
  4. WAIT - it may take 30 seconds to a minute for a window to appear.
  5. A window will eventually appear in which you insert your user name and password.
  6. Click the Send+Done button.
You can start additional xterms by just typing xterm & at the unix prompt in the one xterm you have created.

You can also start up xterm's on curie by clicking the eXceed icon on the tool bar at the bottom (it appears after the first 3 steps above), then clicking Tools/Client Startup/curie.

I must warn you that when we get to chapters 8 and 9, eXceed acts up a bit with graphical Java programs, but the work ok. The eXceed software complains about some fonts, and worse, your Java GUI windows can't be resized and the other eXceed windows get temporarily hung up. The Java program appears (so far) to run ok, and you can still abort it by putting the cursor in the original xterm window and typing control-C.

For more information view Sun's documentation for jdb.


[Homepage] | [General Lab Info] | [TA's & Tutors] | [FAQ's] | [Supplements] | [Homework] | [Excellent Programs] | [Exams]