Note: For lab times goto [TA's & Tutors] page.
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".
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. 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
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.
For more information view Sun's documentation for jdb.
You might also want to look through the CMPS12L lab on using jdb.