Installing the Java Software Development Kit

   

Core Java™ 2: Volume I - Fundamentals
By Cay S. Horstmann, Gary Cornell
Table of Contents
Chapter 2.  The Java Programming Environment


The most complete and up-to-date versions of the Java 2 Standard Edition (J2SE) are available from Sun Microsystems for Solaris, Linux, and Windows. Versions in various states of development exist for the Macintosh and many other platforms, but those versions are licensed and distributed by the vendors of those platforms.

If you use Solaris, Linux, or Windows, you should download the Java Software Development Kit from http://java.sun.com/j2se. Installation directions differ on each platform. At the time of this writing, you can find them on

  • http://java.sun.com/j2se/1.4/install-solaris.html

  • http://java.sun.com/j2se/1.4/install-linux.html

  • http://java.sun.com/j2se/1.4/install-windows.html

graphics/notes_icon.gif

Only the installation and compilation instructions for Java are system dependent. Once you get Java up and running, everything else in this book should apply to you. System independence is a major benefit of Java.

graphics/notes_icon.gif

The setup procedure offers a default for the installation directory that contains the Java SDK version number, such as j2sdk1.4.0. If you prefer, you can change the installation directory to jdk. However, if you are a Java enthusiast who enjoys collecting different versions of the Java SDK, go ahead and accept the default. In this book, we will refer to the installation directory as jdk. For example, when we refer to the jdk/bin directory, we mean the directory named bin under the Java SDK installation directory. Also note that we use UNIX style directory names. Under Windows, you'll have to use backslashes and drive letters such as c:\jdk\bin.

Setting the Execution Path

After you are done installing the Java SDK, you need to carry out one additional step: add the jdk/bin directory to the execution path, the list of directories that the operating system traverses to locate executable files. Directions for this step also vary among operating systems.

  • In UNIX (including Solaris or Linux), the procedure for editing the execution path depends on the shell that you are using. If you use the C shell (which is the Solaris default), then add a line such as the following to the end of your ~/.cshrc file:

     set path=(/usr/local/jdk/bin $path) 

    If you use the Bourne Again shell (which is the Linux default), then add a line such as the following to the end of your ~/.bashrc or ~/.bash_profile file:

     export PATH=/usr/local/jdk/bin:$PATH 

    For other UNIX shells, you'll need to find out how to carry out the analogous procedure.

  • Under Windows 95/98/ME, place a line such as the following at the end of your AUTOEXEC.BAT file:

     SET PATH=c:\jdk\bin;%PATH% 

    Note that there are no spaces around the =. You must reboot your computer for this setting to take effect.

  • Under Windows NT/2000/XP, start the control panel, select System, then Environment. Scroll through the User Variables window until you find a variable named PATH. Add the jdk\bin directory to the beginning of the path, using a semicolon to separate the new entry, like this:

     c:\jdk\bin;other stuff 

    Save your settings. Any new console windows that you start have the correct path.

Here is how you test whether you did it right:

Start a shell window. How you do this depends on your operating system. Type the line

 java -version 

and press the ENTER key. You should get a display such as this one:

 java version "1.4.0" Java(TM) 2 Runtime Environment, Standard Edition Java HotSpot(TM) Client VM 

If instead you get a message such as "java: command not found," "Bad command or file name," or "The name specified is not recognized as an internal or external command, operable program or batch file," then you need to go back and double-check your installation.

Installing the Library Source and Documentation

The library source files are delivered in the Java SDK as a compressed file src.jar , and you must unpack that file to get access to the source code. We highly recommend that you do that. Simply do the following:

  1. Make sure the Java SDK is installed and the jdk/bin directory is on the execution path.

  2. Open a command shell.

  3. Change to the jdk directory (e.g. /usr/local/jdk or C:\jdk).

  4. Execute the command:

     jar xvf src.jar 

graphics/exclamatory_icon.gif

The src.jar file contains the source code for all public libraries. To get even more source (for the compiler, the virtual machine, the native methods, and the private helper classes), go to http://www.sun.com/software/java2.

The documentation is contained in a compressed file that is separate from the Java SDK. You can get to the documentation download site from http://java.sun.com/docs. Several formats (.zip, .gz, and .Z) are available. Choose the format that works best for you. If in doubt, use the zip file because you can uncompress it with the jar program that is a part of the Java SDK. Simply follow these steps:

  1. Make sure the Java SDK is installed and the jdk/bin directory is on the execution path.

  2. Download the documentation zip file and move it into the jdk directory. The file is called j2sdkversion-doc.zip, where version is something like 1_4_0.

  3. Open a command shell.

  4. Change to the jdk directory.

  5. Execute the command:

     jar xvf j2sdkversion-doc.zip 

    where version is the appropriate version number.

Installing the Core Java Program Examples

You also want to install the Core Java program examples. You can download them from http://www.phptr.com/corejava. The programs are packaged into a zip file corejava.zip. You should unzip them into a separate directory we recommend you call it CoreJavaBook. You can use any zip file utility such as WinZip (http://www.winzip.com), or you can simply use the jar utility that is part of the Java SDK. If you use jar, do the following:

  1. Make sure the Java SDK is installed and the jdk/bin directory is on the execution path.

  2. Make a directory CoreJavaBook.

  3. Download the corejava.zip file to that directory.

  4. Open a command shell.

  5. Change to the CoreJavaBook directory.

  6. Execute the command:

     jar xvf corejava.zip 

Navigating the Java Directories

In your explorations of Java, you will occasionally want to peek inside the Java source files. And, of course, you will need to work extensively with the library documentation. Table 2-1 shows the Java directory tree. The layout will be different if you have an integrated development environment, and the root will be different depending on the Java SDK version that you installed.

Table 2-1. Java directory tree

jdk

(the name may be different, for example, j2sdk1.4.0)

 

docs

library documentation in HTML format is here (after expanding j2sdkversion-doc.zip)

 

bin

the compiler and tools are here

 

demo

look here for demos

 

include

files for native methods (see Volume 2)

 

lib

library files

 

src

look in the various subdirectories for the library source (after expanding src.jar)

 

jre

Java runtime environment files

The two most important subdirectories in this tree are docs and src. The docs directory contains the Java library documentation in HTML format. You can view it with any web browser, such as Netscape.

graphics/exclamatory_icon.gif

Set a bookmark in your browser to the local version of docs/api/index.html. You will be referring to this page a lot as you explore the Java platform.

The src directory contains the source code for the public part of the Java libraries. As you become more comfortable with Java, you may find yourself in situations for which this book and the on-line information do not provide what you need to know. At this point, the source code for Java is a good place to begin digging. It is occasionally reassuring to know that you can always dig into the source to find out what a library function really does. For example, if you are curious about the inner workings of the System class, you can look inside src/java/lang/System.java.


       
    Top
     



    Core Java 2(c) Volume I - Fundamentals
    Building on Your AIX Investment: Moving Forward with IBM eServer pSeries in an On Demand World (MaxFacts Guidebook series)
    ISBN: 193164408X
    EAN: 2147483647
    Year: 2003
    Pages: 110
    Authors: Jim Hoskins

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net