ICS 23 / CSE 23 - Setting Up Java At Home


A word of warning

One of the advantages of programming in Java is that it's possible to set up your own computer as a Java development environment easily and cheaply. On the other hand, working in the lab has some genuine benefits, particularly for those of you who are fairly new to programming. In the lab, you'll find that help is more readily available when you get stuck, that your machine setup will generally be stable and designed well for the task of working on your assignments, and that you're free of the distractions of your home.

Nevertheless, I'm aware that many of you, either out of want or need, will choose to do some percentage of your work at home. What follows is enough information to turn your Windows-based machine into a Java development environment at little or no cost.


Getting started

Before you get started, be aware that this document only describes how to set up Java on a Windows machine. If you're using a Macintosh or running Linux, I'm sorry to say that you're on your own -- though you may find that many of the concepts here will translate fairly well to your system.

First and foremost, you need a Java compiler and Java virtual machine. There are several packages that include these tools, but a great option is to download the Java 2 Standard Edition (J2SE) SDK from java.sun.com. J2SE is absolutely free! Remember, you will need a version that is at least as recent as 1.5 (which is also called 5.0). J2SE includes a Java compiler (javac), a Java virtual machine (java), and all of the standard Java library components -- in other words, everything you need to write Java programs in a wide variety of problem domains, and more than enough firepower for the assignments we'll be giving you. Make sure that you download the SDK, not the JRE. The JRE is the Java Runtime Environment, which includes the necessary code to allow you to run Java programs, but not to write and compile them!

Secondly, you'll need a text editor, which you'll use to write and edit your program code. There are many inexpensive and/or free options available. In the lab, we provide TextPad, which you can download from www.textpad.com. TextPad requires a modest registration fee, which you should pay if you plan to use it on a continuous basis. You may be able to find free text editors, particularly those written in Java, at shareware/freeware download sites such as www.download.com.


Installation: the easy part

Presumably, your text editor will include an installation program to set it up and make it completely ready for your use.

J2SE also includes an installation program, which places all of the files into the appropriate places and sets up some desktop shortcuts for you. However, after running the installation program, you still won't be able to execute javac or java, without making a couple of modifications "under the hood" of your system.


The (not all that) hard part: PATH and CLASSPATH

You can execute programs from a Command Prompt (or, as Windows 95/98 call it, an "MS-DOS prompt") by simply typing their names, such as javac or java. But there's a catch: Windows has to know where it can find these programs. This is the job of the PATH environment variable. PATH is a list of folders, separated by semicolons, in which Windows will look for a program whenever you try to execute one.

Similarly, whenever the Java compiler or Java virtual machine need to be able to use a Java class (such as when you import a class from the Java library), the compiler or virtual machine needs to be able to know where to find it. This is the job of the CLASSPATH environment variable. CLASSPATH is a list of folders, separated by semicolons, in which the Java compiler or virtual machine will look for a Java class whenever it's trying to find one.

So, to make J2SE work, you have to modify the PATH and CLASSPATH environment variables on your system, so that Windows will be able to find javac and java, and so that javac and java will be able to find all of the necessary Java classes.

How you modify these variables depends on which version of Windows you're using. In either case, I'll assume that you've installed J2SE into the default directory during installation, which, for the sake of this document, let us assume is C:\jdk1.5.0_01. If you installed it somewhere else, you'll need to use your installation directory instead of the one above.

On Windows 95, 98, and probably ME. (I say "probably" because I don't have a version of ME handy to test this with.) On these versions of Windows, you can set the PATH and CLASSPATH by modifying the file C:\AUTOEXEC.BAT. Add the following two lines to the end of this file:

set PATH=%PATH%;C:\jdk1.5.0_01\bin
set CLASSPATH=%CLASSPATH%;.;C:\jdk1.5.0_01\lib

You'll probably need to restart your system for these changes to take effect.

On Windows 2000 and XP. Right-click the My Computer icon on your desktop and select Properties. Select the Advanced tab. Click the Environment Variables... button. Under "System variables," find the PATH variable and add this to the end of it:

;C:\jdk1.5.0_01\bin

Then find the CLASSPATH variable. If it doesn't exist (and it probably won't, if you've never used your system to develop Java code), click the New... button, specifying CLASSPATH as its name, and the following value:

.;C:\jdk1.5.0_01\lib

You may need to restart your system, or at least start up a new Command Prompt window, in order for these changes to take effect.


That's it!

At this point, you should be good to go. Happy coding!