How to install JDK

  1. Downloading JDK
  2. Installing JDK
  3. Modifying the Path
  4. Setting the class path
The most recent version of the JDK is the JDK 1.3.1 (also known as the Java 2 SDK, Standard Edition, version 1.3.1). We will explain step by step how to install JDK 1.3.1 on your PC running Windows 95 / 98 / 2000 / NT 4.0 (Intel Platform).

Downloading JDK

You can  download the installation file directly from Sun's web site. The address is :
http://java.sun.com/j2se/1.3/download-windows.html

You can choose download the JDK installation file in one piece, or in a number of smaller pieces (floppy size). If you have downloaded the installation file, you can begin the installation process by double clicking on the icon of the file. We suggest you to download in one piece.


Installing JDK

1) The JDK setup program then asks for where you want to install the software etc - choose the defaults. The default directory will be C:\jdk1.3.1. It is a good idea to accept this default option, although you can install in a different location if you choose.

2) When asked for how much you want to install all you really need is the Program Files, but if you have the space available, you should install all the components.


 


Modifying the Path

1) After installing, one of the directories is called "bin". This is where all the executable files, such as java, javac, appletviewer, etc. are
installed. To make it so that you can use all these JDK commands from within any directory, you need to add "c:\jdk1.3.1\bin" to your path.

2) Open the c:\autoexec.bat file in a text editor.

3) Make the PATH equal whatever was the current value followed by C:\JDK1.3.1\bin;.

(Note: it will depend on the version of jdk. If you installed different version, change the jdk1.3.1 to the version that you have installed. Example: C:\jdk1.3\bin; or C:\jdk1.1.8\bin;)
 

4) Now, you need to Save the autoexec.bat file. Next, you need to restart your machine.

5) To make sure you have correctly modified the path, simply print out your path information again, by typing "path" at the command prompt. Your new path should include the "C:\jdk1.3.1\bin" directory, as in the picture below. As a final test to make sure everything has been installed correctly, type "javac" at the command prompt:

If you get the output message "Bad command or file name", then your path has not been modified correctly. If you get the output "Usage: javac <options> <sourcefiles>" followed by a list of possible options as in the screen shot above, then everything is correctly installed, and you are ready to start developing Java programs on your PC!

Note: If you are running Windows NT / 2000, then to modify your path you should start the Control Panel, select System, select Environment, and look for "Path" in the User Variables and System Variables. Add the directory C:\jdk1.3.1\bin to the right hand end of the "Path" variable.


Optional : Setting the classpath

Information

The class path can be set using either the -classpath option when calling an SDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.
    C:> sdkTool -classpath path1;path2...

    -or-

    C:> set CLASSPATH=path1;path2...

    where:

    sdkTool
    A command-line tool, such as java, javac, or javadoc. For a listing, see SDK Tools.

    path1;path2
    Paths to the .jar, .zip or .class files. Each path should end with a filename or directory depending on what you are setting the class path to:


    Classes can be stored either in directories (folders) or in archive files.

    Multiple path entries are separated by semi-colons. With the set command, it's important to omit spaces from around the equals sign (=).

    The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

    Classpath entries that are not either a directory or an archive (.zip or .jar file) are ignored.
     

Example:

There are many different ways to setup the classpath for application and applet.

I will use the example given by the text book (Java Structures: Data Structures in Java for the Principled Programmer Duane A. Bailey) They provide java files with a named package called structure. Also, the working directory is called "course" under C drive.



Example 1:

Features:

I am using the jar file from the above example. The file name is structure.jar. The jar file contains all the class files in the package. Save the structure.jar file under C: drive (actually, you can save in any directory). Now you need to type the following command under DOS.

C:> set CLASSPATH=.;C:\structure.jar;

Now, you can compile and run any application (Test.java) at any directories.

Note:  You don't need to extract all the files from the structure.jar file and it works in application.


Example 2:

Features:

Using the example from above, you can also download the structure.zip file (include the class and java files). Save the structure.zip file under C: drive. Now you need to type the following command under DOS.

C:> set CLASSPATH=.;C:\structure.zip;

Now,  you can also compile and run any application (Test.java) at any directories.

Note: same as example 1, you don't need to extract all files from the structure.zip file.


Example 3:

Features:

1) Download the structure.jar file and save in C:\course directory.

2) You need to set up your classpath so that you can compile the source code. Type the following command in DOS.

C:> set CLASSPATH=.;C:\course\structure.jar;

3) Compile  your file (TestApplet.java)

4) Create html file to load your applet. You must put "ARCHIVE" tag in your html file. Download the TestApplet.html from here.

<html>
<body>
<applet code="TestApplet.class" ARCHIVE="structure.jar" width=200 height=200></applet>
</body>
</html>

5) Now you can run the applet.


Example 4:

Features:

Same as the above example, but if you don't want to set up the "ARCHIVE" tag, you can put the structure.jar file in the "C:\jdk1.3\jre\lib\ext" Folder. This is the default installation directory for Extensions to the Java platform. This is where the JavaHelp jar file goes when it is installed.

Therefore, the steps are:

1) Download the structure.jar file and save in "C:\jdk1.3\jre\lib\ext" folder.

2) Compile your source code (Test.java file).

3) Create a html file .
<applet code="TestApplet.class" width=200 height=200></applet>

4) Run your applet.

Note: You don't need to set up the classpath for applet.


Example 5:

Features:

Steps:
  1. Create a directory name called structure under your working directory (e.g. C:\course\structure). The directory name must be the same as your package name.
  2. Extract all files into the structure directory
  3. Now move back to your working directory (e.g. course)
  4. set the classpath by C:> set CLASSPATH=.;C:\course;
  5. Compile the test program (Test.java or TestApplet.java)
  6. If you have this error message (Package structure not found in import), please contact your demonstrator or tutor to help you to fix the problem. "
  7. If no error message, run the test program.


Note: How to create the JAR file?

JAR files are cross-platform archives that can hold an arbitrary number of files, and are used mostly to store .class files and auxiliary files such as image and audio files. The java tools understand JAR file format and automatically extract what they need. To create a JAR file, use the jar command, which is reminiscent of the Unix tar command, and the following options as needed:

c        create jar file
t        list table of contents
x        extract files
u        update
v        verbose output
f        use file instead of standard
         input/output
m        read manifest file
0        (the numeral zero) turn off
         compression (for faster
         loading)
M        skip manifest
C        change directory (don't
         include path names in output)

To create a JAR file for structure files in c:\structure, you would execute the following command from c:\:

jar cvf structure.jar structure\*.class



Any problems, please email to Angela.
July 2001