Computer Science 235 :: Data Structures and Algorithms

CS 235 Java in Windows Tutorial


The five second How-To

At the command line, type set path=%path%;c:\jdk\bin

Now javac and java should work from the command line just like in Linux.

That's it. See, it really was only five seconds.

If you want to know what you did in the five second How-To

Java is installed on all the Windows machines, but in order to use it you have to tell the computer where to find the Java compiler executable file as well as the Java virtual machine executable file. When you type the name of a program you want to run the computer first looks in whatever directory you are currently in for a file with that name. For example, say I'm in the bob directory on my C drive and I type the name of a program I want to run like this:

C:\bob\acoolfilename.exe

When I press enter the computer will look in the bob directory to see if there is a file with that name. If there is it will try to run it. But if there isn't a file with that name then what does the computer do? Does it just give up? Well, a lot of times computers do that, but not in this case. The operating system has what's called a path environmental variable. This variable contains a list of paths where the computer should try to find files if it can't find them in the current directory. To find out what paths the variable currently has on your computer open a command prompt and type path On my computer at home this prints out PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\Wben Yours will probably look different, and that's okay. Now, it's all fine and dandy to find out what's in the path variable, but what would really be helpful is knowing how to change it, right? Well, that's what the command in the five second How-To does. The set command tells the operating system that you want to change one of the environmental variables (there are others besides just PATH, but we don't care about them at the moment). Then you tell it what variable you want to set and what value you want it to have. So if for some reason you wanted to you could type set waldo=ralph In this case the variable waldo would have the value ralph. Wonderful, isn't it? (Now, exactly what you'd do with such a useful variable as this is another matter entirely.) Now the only other item of interest in the five second How-To above is that %path% business. What does that do? Well, that's one example of how to use a variable that's already set up. When you put the %'s around a word that tells the operating system that you want to treat that word as a variable and not as a directory or filename or something like that. So what our example above tells the operating system that we're going to set the PATH variable and the value we want to set it to is what it already had (the %path% part) and then add the c:\jdk\bin path to the list of paths that should be searched for file names.

Ta-dah! That's all there is to it. Everything you ever wanted to know about that (plus some probably).


Last updated January 6, 2003