Java Reference
In-Depth Information
If you want the JDK documentation installed in the hierarchy shown in Figure 1-1 , then you should ex-
tract the documentation from the archive to the jdk1.7.0_n directory. This creates a new subdirectory, docs
(or possibly docs_www ), to the root directory, and installs the documentation files in that. To look at the doc-
umentation, you just open the index.html file that is in the docs subdirectory.
Extracting the Source Code for the Class Libraries
The source code for the class libraries is included in the archive src.zip that you find in the jdk1.7.0 root
directory. Many Java IDEs can access the contents of this zip directly without unpacking it. After you have
learned the basics of the Java language, browsing this source is very educational, and it can also be helpful
when you are more experienced with Java in giving a better understanding of how things work — or when
they don't, why they don't.
You can extract the source files from the src.zip archive using the Winzip utility, the WinRAR utility,
the JAR utility that comes with the JDK, or any other utility that unpacks .zip archives — but be warned
— there's a lot of it, and it takes a while!
Extracting the contents of src.zip to the root directory \jdk1.7.0 creates a new subdirectory, src , and
installs the source code in subdirectories to this. To look at the source code for a particular class, just open
the .java file that you are interested in using with your Java program editor or any plain text editor.
Compiling a Java Program
Java source code is always stored in files with the extension .java . After you have created the source code
for a program and saved it in a .java file, you need to process the source using a Java compiler. Using the
compiler that comes with the JDK, you make the directory that contains your Java source file the current
directory, and then enter the following command:
javac MyProgram.java
Here, javac is the name of the Java compiler, and MyProgram.java is the name of the program source
file. This command assumes that the current directory contains your source file. If it doesn't, the compiler
isn't able to find your source file. It also assumes that the source file corresponds to the Java language as
defined in the current version of the JDK. There is a command-line option, -source , that you can use to
specify the Java language version, so for JDK 7, the preceding command to execute the compiler is equival-
ent to the following:
javac -source 1.7 MyProgram.java
In practice you can ignore the -source command-line option unless you are compiling a Java program
that was written using an older version of the JDK. You get the current source version compiled by default.
To compile code written for JDK 6 you would write:
javac -source 1.6 oldSourceCode.java
Here's a simple program that you use to can try out the compiler:
Search WWH ::




Custom Search