In order to compile and run Java programs on a computer, the computer needs to be able to find the java programs you will use - javac.exe for compiling source, and java.exe for running Java programs. In order for this to work, your PATH environment variable must be set properly. The Java programs, in turn, will need to know where to look on your computer to find .class files needed to resolve references. These references include custom classes that you write as well as classes written by developers at Sun (for example: java.util.HashMap or java.lang.String). In order for this to work, your CLASSPATH environment variable must be set properly. These instructions refer to something called the - this is the directory that you installed the Java SDK into. For most of you, that will typically be c:\jdk1.3.1 or c:\program files\jdk1.3.1 Replace with the actual directory you installed into. YOU MUST INSTALL THE JDK TO COMPILE JAVA SOURCE FILES ON YOUR COMPUTER. To install the JDK: Insert the CD that came with the book into your CD drive. Go to ... \software-win\sj-sdk\j2sdk-1_3_1-win.exe. To set your path variable: -------------------------- There are various places you can "permanently" set environment variables[1] on the different versions of Windows, but the following steps, when carried out at a command prompt will always work *for the duration of that command prompt*: set PATH=%PATH%;\bin; example: set PATH=%PATH%;c:\jdk1.3\bin; To set your classpath variable: ------------------------------ Again, you may eventually figure out how to permanently set this variable, but it will always work that if you type the following commands into a command prompt, the classpath variable will be set correctly for the duration of that command prompt: This line makes sure all the standard Java classes are available to you - it is not technically required unless you are using a program like Jikes.exe to compile. set CLASSPATH=\jre\lib\rt.jar This next line adds the CURRENT DIRECTORY (this changes as you change directories) to the classpath as well. Dot represents the current directory. set CLASSPATH=%CLASSPATH%;. If you do not wish to (or cannot for some reason) set the classpath at the command prompt, you can always specify it each time you invoke java.exe or javac.exe by adding the -classpath switch to the javac.exe program, or the -cp switch to the java.exe program. For EXAMPLE: javac -classpath c:\jdk1.3.1\jre\lib\rt.jar;.; -d . *.java Remember, this is an example only, you may have installed the JDK into a different directory (see JAVA_INSTALL_DIR discussion above). As your work on the class project progresses, you will need to use classes and interfaces that I have written for you. They are available for download from the website in a jar file named partone.jar. The preferred way of using classes packaged in a jar file is to simply add the jar file to your classpath. Note that I have adapted the previous command to now use the partone.jar file as part of the classpath: javac -classpath c:\jdk1.3.1\jre\lib\rt.jar;.;partone.jar -d . *.java The command above assumes that you have saved the partone.jar file in the same directory as your source code. You could have saved it to another directory though: javac -classpath c:\jdk1.3.1\jre\lib\rt.jar;.;c:\downloads\partone.jar -d . *.java In this last case, the partone.jar file was saved to the c:\downloads directory. To compile: ---------- Remember that we always place our source/classes in packages, so you will need to rememeber to compile with the -d flag telling javac where to start creating the directory tree that mimics the package structure. Since the current directory is in the classpath (from step #2 of classpath instructions), the following is a suitable command: javac -d . Remember to add the .java extension - this is the FILENAME of the source you want to compile, not the name of the class. To run: ------ Make sure you are running your program from the same directory that you compiled it from. java Remembed to OMIT the .class extension. This is the CLASSNAME not the FILENAME of the class. If you understand how classpaths work, you should understand how to adapt these instructions to always compile your source files to a common base directory. Basically, as long as the directory that you pass to the -d . switch when you compile is also listed in your classpath, you will be OK. For example: C:\ | +--- cis218 | + classes | | | + edu | | | + cod | | | + cis218 | | | + Source1.class | + Source2.class | + Source3.class + source | + Source1.java + Source2.java + Source3.java In this example, the compilation command would be as follows (from the c:\cis218\source directory): javac -d c:\cis218\classes *.java Then to run one of the classes (let's say that Source1.java includes a public static void main(String[] args) method): java -cp c:\cis218\classes edu.cd.cis218.Source1 You may also elect to keep your source files in directories that mirror their package structure as well (this is a common and well-accepted practice in real life). [1] Windows 98: Start | Run | msconfig Set the variables as above under the AUTOEXEC.BAT tab Windows NT: Start | Settings | Control Panel | System Set the variables as above under the ENVIRONMENT tab Windows 2000: Similar to NT, I think, but may be the ADVANCED tab Windows XP: Don't know off the top of my hea