The Java 2 Software Development Kit (Java SDK)

Introduction

The Java 2 SDK (Termed Java 2 by SUN, referring to JDK 1.2.x or JDK 1.5.x) Standard Edition is available freely at http://java.sun.com/j2se/. This year, for the first year, I recommend that you download JDK 1.5. We will hopefully touch on some of the new features of this JDK such as, Metadata, Generics, Enumerated types and Autoboxing of primitive types.

The JDK provides the basic tools of:

  • javac - The Java programming language compiler.

  • java - The run-time environment for developed Java applications.

  • appletviewer - A basic Java enabled browser.

  • javadoc - Automatic API documentation tool.

  • jdb - The embedded Java debugging tool.

  • javah - A native development tool for creating C headers.

  • javap - A class file disassembler.

It also includes a set of advanced tools for performance analysis, security, Remote Method Invocation (RMI) and internationalisation.

The Java 2 Platform features are illustrated in Figure 4.2, “The Java 2 Platform Overview (Figure from java.sun.com)” [9] .

Figure 4.2. The Java 2 Platform Overview (Figure from java.sun.com)

The Java 2 Platform Overview (Figure from java.sun.com)

Installation of the Java 2 Software Development Kit

The latest release of the Java 2 Software Development Kit is Java JDK 6. To install this on your home PC, please take the following steps:

  • Download the Java Development Kit from: http://java.sun.com/j2se/1.5.0/download.jsp. You do not have to download netBeans if you follow the red image link to the right for "J2EE Download the SDK". When you follow the link, about a quarter the way down the page you will see a link for J2SE 5.0 Download, under the "Separate Bundles" heading. Follow this link, accept the license and choose "Windows off-line installation" - it is approximately 51MB in size.

  • Download the J2SE 5.0 Documentation from the same page (half way down): http://java.sun.com/j2se/1.5.0/download.jsp. Press the download button (not view).

  • Execute the installation (.exe) file and allow it to complete a full install. Choose the default directory, or a shorter one, such as c:\j2sdk1.4. For the remainder of these instructions, I will assume you have chosen c:\j2sdk1.4.

  • Extract the documentation to a suitable directory, for example: c:\j2sdk1.4\docs using a .zip extractor. If you do not have one installed, use winzip (http://www.winzip.com/).

  • You should not have to do this step - test first!Set your PATH to include the bin directory of the installed folder (e.g. c:\j2sdk1.4\bin). See Figure 4.3, “Setting the Java Environment Variables.”.

  • You should not have to do this step - test first!Set a new CLASSPATH environment variable to include the file c:\j2sdk1.4\jre\lib\rt.jar and the current directory - so it should have the form

       .;c:\j2sdk1.4\jre\lib\rt.jar
    		

    See Figure 4.3, “Setting the Java Environment Variables.”. This is my setting on Windows XP Professional.

There is a comprehensive SUN guide to installation at: http://java.sun.com/j2se/1.4.1/install-windows.html.

Figure 4.3. Setting the Java Environment Variables.

Setting the Java Environment Variables.

Testing the JDK

To test the JDK, we will use the Hello World application. Here is the source code:


 public class HelloWorld
 {
   public static void main(String args[])
   {
     System.out.println("Hello World!");
   }
 }

To compile and run this application, perform the following steps:

  • Open Notepad, or any other text editor (not MS Word) and paste the code above into the editor.

  • Save the as HelloWorld.java. The HelloWorld class must be placed in a file of the same name. Note: if you are using notepad, please place inverted commas around the file name (e.g. "HelloWorld.java") or it may be saved as HelloWorld.java.txt.

  • Compile the (.java) source file, by typing "javac HelloWorld.java". If you receive a "command not found" error then your PATH environment variable may be incorrect. Any other errors could mean that your CLASSPATH is incorrect.

  • Execute the (.class) bytecode file, by typing "java HelloWorld". Note that the file-type extension is omitted and the exact case must be supplied (i.e. capital H and W).

See Figure 4.4, “Testing the JDK.” to see this code example working on my PC.

Figure 4.4. Testing the JDK.

Testing the JDK.

If you get the same results - you have installed everything correctly - congratulations!

The Java Runtime Environment (JRE)

The Java JDK 6 release also included the Java Runtime Environment (JRE), that consists of the JVM, the Java platform core classes, and supporting documentation. The JRE is aimed at developers who wish to distribute their applications with a runtime environment. The SDK is large and licensing also prevents the distribution of the JDK.



[9] Image from: Java 2 SE Introduction Documentation ( http://java.sun.com/j2se/1.4.2/index.html)