Installing J2SE 1.4.2 (Java 2 Platform, Standard Edition), MS Windows version

The sections below describe how to install the basic facilities needed to get started with Java. You should be familiar with installing programs on your PC and how to set environment variables in your autoexec.bat file (Win98,ME) or via the environment variables dialog (Win2K, XP).

J2SE 1.4.2 (also known as JDK 1.4.2) is the development kit for the most recent version of Java at the time this page was written. It requires about 250 Mbytes of disk space, including all the documentation.

The JDK is distributed as the file j2sdk-1_4_2_01-windows-i586.exe (this is updated on a regular basis so a more recent version many now be available). The JDK can be downloaded from http://java.sun.com or is on the Teaching CD available from the Departmental Office room G14 (the CD costs 1). The documentation is distributed in the file j2sdk-1_4_2-doc.zip.

Installing the JDK

To install the JDK read the instructions below and the instructions on SUN's website http://java.sun.com/j2se/1.4.2/jre/install.html.

To install under Windows, first run the file j2sdk-1_4_2_01-windows-i586.exe and follow the instructions displayed. Then unzip the documentation file j2sdk-1_4_2-doc.zip into the directory where you installed the JDK (by default this will be c:\j2sdk1.4.2_01). To display the documentation, locate the file index.html in the j2sdk1.4.2_01\docs directory and double-click it. The index page will then open in your web browser - make sure you bookmark it.

After the JDK is installed you need to add the j2sdk1.4.2_01\bin directory to your path environment variable if not already present, otherwise the tools won't be found when you try to compile and run programs.

On Windows 98/ME systems, do this by editing your autoexec.bat file in your c:\ directory, or create it if it doesn't exist. Add the following line:

set PATH=%PATH%;c:\j2sdk1.4.2_01\bin

(make sure the directory name matches where you installed the JDK). If there are no other lines setting PATH then you can simply use:

set PATH=c:\j2sdk1.4.2_01\bin

Then reboot.

On Windows 2000 systems locate the environment variables dialog by right-clicking the MyComputer icon on the desktop and selecting Properties to display the System Properties dialog. Then select the Advanced tab and click the Environment Variables button. In the Environment Variables Dialog, locate and double-click the variable called Path in the System Variables section. At the end of the path add:

 ;c:\j2sdk1.4.2_01\bin

Don't leave out the semi-colon and change the path if you installed the JDK at a different location.

On Windows XP systems locate the environment variables dialog by selecting the System option in the Control Panel. Then select the Advanced tab and click the Environment Variables button. In the Environment Variables Dialog, locate and double-click the variable called Path in the System Variables section. At the end of the path add:

;c:\j2sdk1.4.2_01\bin

Don't leave out the semi-colon and change the path if you installed the JDK at a different location.

Setting the CLASSPATH

As you start using Java, especially if you use third-party class libraries, you may also need to set your CLASSPATH environment variable. On Windows 98/ME, this is done by editing your autoexec.bat file (as above) and adding a line like:

SET CLASSPATH=.;c:\someclasses\stuff.jar

or, if a CLASSPATH entry already exists then a new line like

SET CLASSPATH=%CLASSPATH%;c:\someclasses\stuff.jar

Use your own path rather than the example given. As many paths as you need can be added, with each separated by a semi-colon.

Make sure the . (i.e., dot standing for current directory) appears in your CLASSPATH, otherwise you will find that things won't work properly. You need to reboot before the changes take effect.

For Windows 2000 and XP systems, open up the Environment variables dialog (as above) and either edit the CLASSPATH entry in the System Variables section or add a new variable if CLASSPATH has not yet been defined.

Always make sure that . (i.e., dot) appears in your CLASSPATH.

On Windows 98/ME systems, if the amount of information in your PATH or CLASSPATH variables starts to get large, you may start to see error messages saying you have run out of environment space. This can be fixed by editing your config.sys file (also found in the root directory of your C: drive) and making sure it has a line like: shell=comand.com /e:8192 /p. The same can be achieved by editing the properties of .pif files. The /e:8192 /p bit allocates more space for environment variables and will get rid of the error messages.

Installation Problems

The JDK should install without problem but if you do have difficulties the most likely causes are:

Incorrect path names when you set PATH and CLASSPATH.
Dot (i.e., the character '.') missing from your CLASSPATH. This will prevent programs running. A common cause of this problem is installing some other piece of software that sets or changes your CLASSPATH variable without you knowing.
Spaces in file and directory names. If possible avoid spaces and don't install the JDK in your Program Files directory.

Using a JDK

The JDK tools, such as the javac compiler and the java runtime, are command line based and should be run from a DOS prompt (Win 98/ME) or a Command Prompt (Win 2000/XP), or a shell like Bash if you have it installed. Do this by opening one or more DOS/Command Prompt windows. With older versions of Windows it is a good idea to have the doskey utility installed to save typing.