Sunday, September 4, 2011

Installing Java Standard Edition Development Kit (JDK) and Setting the PATH Environment Variable

Installing Java Standard Edition Development Kit (JDK)

From my next post, we shall start running Java applications. Before you can start running applications, you must first install the Java Standard Edition Development Kit (JDK) 6 or a Java Development tool that supports Java SE 6 (Example like NetBeans IDE). I shall also explain how to install and run your first application on NetBeans IDE.

You can download the JDK 6 and its documentation from Click on the download button for JDK 6. You must accept the license agreement before downloading. Save the installer for your platform on your hard disk and keep track of where you saved it. Before installing, carefully read the JDK installation instruction for your platform, which are located at the following url  After downloading the JDK installer, double click the installer program to begin installing the JDK. I recommend that you accept all default installation options. On Windows, the JDK is placed in the following directory by default.

C:\Program Files\Java\jdk1.6.0

Setting the PATH Environment Variable

The PATH environment variable on your computer designates which directories the computer searches when looking for applications, such as the applications that enable you to compile and run your Java application (called javac.exe and java.exe, respectively). You will now learn how to set the PATH environment variable on your computer to indicate where the JDK’s tools are installed.

  1. On Microsoft Windows XP, you can get the System Properties by clicking on Start, Control Panel and System while on Windows Vista; you can get to the System Properties by clicking on Start, Control Panel, System and Advanced System Settings.
  2. Opening the Environment Variables dialog. Select the Advanced tab at the top of the System Properties dialog. Click the Environment Variable button to display the Environment Variable dialog.
  3. Editing the PATH variable. Scroll down inside the System variable box to select the PATH variable. Click the Edit button. This will cause the Edit System Variable dialog to appear.
  4. Changing the PATH. Place the cursor inside the Variable Value field. Use the left arrow key to move the cursor to the beginning of the list. At the beginning of the list, type the name of the directory in which you laced the JDK followed by \bin; if you installed in the default directory then add this. C:\Program Files\Java\jdk1.6.0\bin; to the PATH variable. Spaces are not allowed before or after each value in an Environment Variable. Click OK button to apply your changes to the PATH variable
If you do not set the PATH variable correctly, when you use the JDK’s tools, you will receive a message like:

‘java’ is not recognized as an internal or external command, operable program or batch file.

If this happens, go back to the PATH environment variable. If you downloaded a newer version of JDK, you may need to change the name of the JDK’S installation directory in the PATH variable.

Setting the CLASSPATH Environment Variable

if you attempt to run a Java program and receive a message like

Exception in thread “main” java.lang.NoClassDefFoundError: YourClass

Then your system has a CLASSPATH environment variable that must be modified. To fix the preceding error, follow the steps in setting the PATH environment variable, to locate the CLASSPATH variable, then edit the variable’s value to include
At the beginning of its value (with no space before or after these characters). 

No comments: