The most complete and up-to-date versions of the Java 2 Standard version (J2SE) are available from Oracle 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 . Installation directions differ on each platform. At the time of this writing, you can find them on

Java graphics notes_icon

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

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 tutorial, 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.

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 version 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
    
Java graphics exclamatory_icon

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 .The documentation is contained in a compressed file that is separate from the Java SDK. You can get to the documentation download site from . 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 . 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 (), 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. 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 filesThe 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.Java graphics exclamatory_icon

Set a tutorialmark 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 tutorial 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.