% javac -g Foo.javaThe -g command line option is optional, but we recommend using it as it makes debugging easier.
If there are no errors in your source file, the Java compiler will produce one or more .class files (one .class file for each class defined in the Foo.java source file). For example, the results of a successful compile of Foo.java will produce a byte-code version of the class in a file named Foo.class.
Every public class that you write must be in a separate .java file where the first part of the file name is identical to the class name. The .java file additionally can contain code for protected and private classes.
We suggest that you get in the habit of using makefiles for compiling your Java application code. More information on makefiles is available here.
% java <class with main method to run> [<command line args>, ...]For example, to run the main method from the Foo class:
% java FooAny command line arguments (arguments to Foo's main method) follow the class name:
% java Foo 10 20
After the first few weeks of class, we will start using the book's JDSL library, and you will need to add this library's JAR file to your CLASSPATH. To your .cshrc file, add the following:
setenv CLASSPATH ./:/home/newhall/public_html/cs35/book_classes/lib/jdsl_general.jarEach path is separated by a ':'. In this example, CLASSPATH is set to two directories: the current directory (./) and the dsl_general.jar file. If you have a CLASSPATH environment variable defined, then the VM uses the paths listed in the CLASSPATH environment variable rather than searching using its default paths. As a result, if you set this environment variable you need to add the current path otherwise the VM will not find classes in the current working directory.
java -Djava.compiler=NONE blah
Compile with -g. This will cause the java compiler to put Java source
code line information in .class files:
javac -g blah.java
jdb <classname>
: to run JDB
exit
: to exit from JDB
run <classname>
: to run your program from within JDB
run <classname> <args>
: to run your program with command-line arguments
If all else fails, add debugging output statments to your code.