Data Structures and Algorithms
Windows/Unix/MacOS-X HOW-TO for Java
Step 1: Download JDK
Download the Java SDK from http://java.sun.com. Notice the difference between the Java Runtime Environment (JRE) and the Java Software Development Toolkit (JDK). JRE does not have the ability to compile java files, while JDK does. Download and install JDK, not JRE. If you are on windows, note the directory where you installed JDK. For example, I installed it at c:\Program Files\jdk.Step 2: Download textbook programs
Go to http://www.cise.ufl.edu/~sahni/dsaaj/ and download progs.zip or eprogs.zip (recommended). Unzip the downloaded file to a local directory. For example, I could unzip eprogs.zip in c:\code on windows or /homes/amyles/code on Unix and MacOS X.Step 3: Setting the environment variables
In order to be able to compile your java code from any directory and to be able to use the textbook programs from any directory, you need to set the PATH and CLASSPATH environment variables appropriately. How you do this depends on the specific operating system you are running.Windows 95/98/ME
Edit c:\autoexec.bat in a text editor (like notepad). You need to append the path to include the bin directory in your jdk installation. For me, this bin directory is c:\Program Files\jdk\bin, and I would have to add the following line to my autoexec.bat file:set PATH=c:\Program Files\jdk\bin;%PATH% Additionally, you will need to append the working directory (.) and the textbook program directory (c:\code for me) to the CLASSPATH as follows:
set CLASSPATH=.;c:\code;%CLASSPATH% Now, as it typical for Windows 95/98/ME, you will have to restart your computer for the settings to take permanent effect.
Windows NT/2000/XP
Go to Start&rt;Settings&rt;Control Panel. Double-click System and go to the Advanced tab. Click Environment Variables. In the dialog box that shows up, you will be able to see the User Variables and the System Variables. In the System Variables, choose the PATH variable and click edit. For the variable value, append the JDK bin directory to the path. For example, if your PATH value is '%SystemRoot%;%SystemRoot%\system32', you want to change it
(in my case) to 'c:\Program Files\jdk\bin;%SystemRoot%;%SystemRoot%\system32'. Similarly, append the CLASSPATH, or if there is no CLASSPATH variable (quite possible) create a new variable named CLASSPATH. Append the working directory (.) and the textbook code directory (c:\code for me) to the CLASSPATH. For example, if I didn't have a CLASSPATH variable, I would create one (as either a system variable or a user variable) with the value '
.;c:\code'.
Unix/MacOS X
The PATH variable should not need setting. You can verify that by typing 'which java' and 'which javac', which should return the locations of these programs. The CLASSPATH environment variable still needs to be set. I will assume that you unzipped eprogs.zip in /homes/amyles/code. You need to edit your shell's settings file. For example, if you use csh, tcsh, bash, or zsh, you should have a corresponding settings file (.cshrc, .tcshrc, .bashrc, or .zshrc, respectively) in your home directory (/homes/amyles for me). To find out which shell you are using, open up a shell prompt and type 'echo $SHELL'.Once you have located your shell settings file, edit it in your favorite text editor and add the following line to the end of it:
For csh and tcsh
setenv CLASSPATH .:/homes/amyles/code:${CLASSPATH}
For bash and zsh
export CLASSPATH=.:/homes/amyles/code:$CLASSPATH
Test your settings
Open up a command/shell prompt and go to your textbook directory (c:\code or /homes/amyles/code for me). Enter the dataStructures directory. Run the following commands at the prompt (NOTE: capitalization does matter!):c:\code\dataStructures> javac ArrayLinearList.java c:\code\dataStructures> java dataStructures.ArrayLinearList Initial size is 0 The list is empty List size is 4 The list is [1, 2, 4, 6] The index of 4 is 2 3 not found Element at 0 is 1 Element at 3 is 6 2 removed The list is [1, 4, 6] 6 removed The list is [1, 4] The list is not empty List size is 2If your PATH and CLASSPATH settings are correct, the above commands should execute properly. You can verify your PATH and CLASSPATH settings at the command/shell prompt as follows:
c:\code\dataStructures> echo %PATH% c:\Program Files\jdk\bin;C:\WINDOWS;C:\WINDOWS\system32 c:\code\dataStructures> echo %CLASSPATH% .;c:\code /homes/amyles/code/dataStructures$ echo $CLASSPATH .;/homes/amyles/code