This document will cover how to install the Java Runtime Kit for home use and ...
Figure 4: Java Runtime Environment installation. Figure 5: Finishing Window. 5 ...
Installing the Java Runtime Kit (JDK) J. Nakamura
1
1
Introduction
This document will cover how to install the Java Runtime Kit for home use and also install the appropriate acm files that will be used in CS 1MD3. The operating system is Windows XP. Knowledge of directory manipulation, file manipulation and unpacking of files (e.g. zip files) are required. If you don’t know how to do this, then ask your TA or come to the Drop-In Centre in ITB 242.
2
Getting Started
To do the installation, the following will be needed: • A Java Runtime Kit. • A jar file created by Association for Computing Machinery (Java Task Force) • A java file to test. All these files should be on the CS1MD3 website. At the time of writing this document, the current JDK is jdk-6u21-windows-i586.exe. If there happens to be a new version, you should be able to use it. The jar file is called acm.jar and the file hello.zip contains some java files that make use of the acm.jar file.
2
3
Installing the JDK
To start the installation, double click on jdk-6u21-windows-i586.exe and an initial installation window pops up. Figure 1 shows the window. NOTE: In previous versions, a licensing agreement window popped up. This time it did not. If one does come up, click on the appropriate agreement button.
Figure 1: Initial Splash Page
3
The next window to appear should be the one that allows the user to change installation preferences (Figure 2). The Java DB option is not needed and does not have to be installed. Click on that option and select the option to not install it (Figure 3). IMPORTANT: make a note of where the JDK is being installed. This will be needed later.
Figure 2: What and where to install
Figure 3: Do not install Java DB Once the Java DB option has been unselected, click on the Next button to continue with the installation. 4
The next window should be where the Java Runtime Environment is going to be installed. You can change where to install it, but it is suggested to use the default (Figure 4). If all goes well, the finishing window should appear (Figure 5).
Figure 4: Java Runtime Environment installation
Figure 5: Finishing Window
5
4
Setting up acm.jar
The next step is to install the acm.jar file. If it not with this file, then it can be downloaded from: http://jtf.acm.org/ This site also contains tutorials and documentation. Once you have the acm.jar file, do the following: 1. Go to the top level (root) of your hard drive (most likely C:) and create a folder (directory) called acm. 2. Copy the acm.jar file into the acm folder.
5
Setting up Environment Variables
To change environment variables, right mouse click on My Computer . At the bottom of the menu, select Properties. Click on the Advanced tab (Figure 6). Click on the Environment Variables button.
Figure 6: System Properties
6
As shown in Figure 7, environment variables come in two varieties, User and System.
Figure 7: Environment Variables window User environment variables are set up and are available only for the user who is logged in. Every user account can have their own set of environment variables. System environment variables are available to all users. Therefore, if you are the only one using your machine, then either area is okay. If other users are using the machine, then it would be easier to put the environment variables in the System variables area. Keep in mind that if you make a mistake in the System area, it will affect everyone. In this example, the system variables will be used. The two environment variables that will be used are classpath and path. Notice from Figure 7, the path variable already exists. This will most likely be the case. The classpath variable will most likely not exist.
7
Scroll through the System variables and find the path variable. Click on that variable so that it is highlighted and then click on the Edit button. Double clicking on the variable works as well. Figure 8 show the editing window that will show up. Go to the end of the string in the Variable value input box. If the is no semi-colon at the end of the string, then add one. Enter the path of where the JDK was installed (see Figure 2). You’ll need to add an extra directory called bin at the end. In this example, the path is c:\Program Files\Java\jdk1.6.0_21\bin;. Enter this value and then press the OK button.
Figure 8: path variable window For the classpath variable, see if it is there. Double click if it is there, otherwise click on the New button. Figure 9 shows the New variable window. In the Variable name box, enter classpath. In the Variable value box, enter the following: .;c:\acm\acm.jar;. If classpath already exists, then add a semi-colon, if not there, to the end of the string and then enter the value. Press the OK button when string has been entered.
Figure 9: classpath variable window Briefly, the path variable is used to help the operating system find programs to run and the classpath variable is used for the Java environment to find classes.
8
6
Testing the Setup
Create a folder (directory) on the root level and call it cs1md3. Unpack the hello.zip file into this directory. Bring up a command prompt by clicking on start and then click on Run. Enter the command: cmd. There is also a command prompt in the Accessories folder. Figure 10 shows a command prompt window.
Figure 10: Command prompt window Figure 10 also shows how to change into a directory. In the example, cd \cs1md3 moves into the cs1md3 directory. The dir command lists the contents of a directory. There should be three java files unpacked from the hello.zip file. To compile a Java program, use the command: javac. If you have set up the environment variables correctly, there should be no errors when the command: javac HelloConsole.java is entered. To run a Java program, use the command: java. When the command: java HelloConsole is entered, a new window will open up and you will see the results. Close the window to get back to the command prompt. If you were successful in compiling and running HelloConsole, then you should be able to compile and run a Java program from the command prompt from any directory. Try compiling and running the other two programs. If you are having problems, talk to your TA(s) or come to the Drop-In Centre in ITB 242.
9