The CD-ROM has the following directory structure:
COREJAVA
WINDOWS
SOLARIS
Other operating systems may be added.
The COREJAVA
directory contains the sample files for both volumes of Core Java. The WINDOWS
directory contains the Java development kit (JDK) for Windows 95/NT and a number of useful shareware programs. The remaining directories contain the JDK for those operating systems.
You can skip this step if you already have a Java 1.1 development environment installed.
Locate the subdirectory on the CD-ROM that matches your operating system.
You will find an installation file for the JDK in a format that is appropriate for your operating system, perhaps accompanied by installation instructions. For example, for Windows, this will be a setup file.
Install the JDK files onto your computer, following the procedure that is appropriate for your operating system. We recommend that you place them inside a directory jdk
. If you have an older version of the JDK, completely remove it before installing the newer version.
If the JDK is installed by a setup program, the setup program usually offers a different default for each version of the JDK, such as jdk1.1.4
. We recommend that you change the directory to jdk
. However, if you are a Java enthusiast who enjoys collecting different versions of the JDK, go ahead and accept the default.
Add the jdkin
directory to the PATH
. For example, under Windows 95, place the following line at the end of your AUTOEXEC.BAT
file:
SET PATH=c:jdkin;%PATH%
Add an environment variable CLASSPATH
. This environment must contain
jdk\lib\classes.zip
the current directory (.
)
CoreJavaBook
(the directory into which you will install the Core Java examples)
For example, under Windows, you add the following line to your AUTOEXEC.BAT
file:
SET CLASSPATH=c:jdklibclasses.zip;.;c:CoreJavaBook
If you use the C shell under Unix, place the following command in your .cshrc
file.
setenv CLASSPATH /jdk/lib/classes.zip:.:$home/CoreJavaBook
Check whether there is a separate installation for the Bean Development Kit (BDK) for your operating system on the CD. If so, install the BDK. We recommend that you install it in a directory bdk
.
Log out or reboot your computer.
Skip this step if you do not use Windows 95 or NT.
We include a number of shareware programs on the CD-ROM that you may find useful, including
WinZip, our favorite ZIP tool. You can use it to uncompress files in the ZIP, JAR, and TAR formats.
TextPad, our favorite ASCII text editor for Windows. This version of TextPad is enhanced to compile and run Java programs. (Look in the Tools menu for the commands.)
HexWorkshop, our favorite hex editor. In Volume 2, we show you how to use HexWorkshop to snoop inside class files.
Keep in mind that the shareware programs are not free; you are expected to pay its authors if you use the program. We have no connection whatsoever with the authors of these programs. We simply found them very useful and thought you might want to give them a try yourself. If you have trouble installing or using these programs, check out the Web pages of the vendors. We offer no technical support for these products.
To install the software, locate the installation files in the subdirectory of the WINDOWS
directory (such as WINDOWSWINZIP
or WINDOWSTEXTPAD
) and run the setup program in that subdirectory.
The CD-ROM contains the source code for all example programs in the book. All files are packed inside a single ZIP archive, COREJAVA.ZIP
.
If you have a ZIP utility such as WinZip (which is supplied on the CD-ROM), you can use it to unzip the files. Otherwise, you need to first install the JDK, as previously described. The JDK program jar
can uncompress ZIP files.
Here are the steps to install the Core Java example files:
Uncompress the COREJAVA.ZIP
file into the CoreJavaBook
directory. You can use WinZip, another ZIP utility, or the jar
program that is part of the JDK. If you use jar
, do the following:
Make a directory CoreJavaBook
.
Copy the COREJAVA.ZIP
file to that directory.
Change to that directory.
Execute the command jar xvf COREJAVA.ZIP
.
Make sure that the CoreJavaBook
directory is on the class path. If you installed the JDK, following our instructions, then the class path will contain the CoreJavaBook
directory. Otherwise, you need to add it.
Many integrated Java development environments have their own methods for setting the class path. If you use such a product, find out how to tell it to search the CoreJavaBook
directory for class files. Consult the documentation of your environment and contact the vendor for assistance if necessary.
The example files are organized as follows:
CoreJavaBook corejava docs ch2 Welcome WelcomeApplet ImageViewer ch3 FirstSample LotteryOdds LotteryDrawing Mortgage MortgageLoop Retirement SquareRoot . . . v2ch1 . . .
There is a separate directory for each chapter of this book. Each of these directories has separate subdirectories for example files. For instance, CoreJavaBookch2ImageViewer
contains the source code and sample images for the image viewer application. (There is no source code for Chapter 1.) The directories for Volume 2 are named v2ch1
, v2ch2
, and so on.
The corejava
directory contains a number of useful Java classes we wrote to supplement missing features in the standard Java library. These files are needed for many examples in the book. It is crucial that your CLASSPATH
environment variable is set to include the CoreJavaBook
directory so that the programs can find our files, such as CoreJavaBookcorejavaFormat.class
and CoreJavaBookcorejavaCloseableFrame.class
.
The docs
directory contains the documentation for the classes in the corejava
directory. Point your Web browser to CoreJavaBookdocs ree.html
for a summary of the utility classes that we supply. Click on the links to get more information about each class.
Go to the CoreJavaBookch2Welcome
directory. Then, enter the following commands:
javac Welcome.java java Welcome
Or, if you use an integrated development environment, load the file Welcome.java
, then compile and run the program. There should be no warning or error messages during compilation.
When the program runs, it should write a welcome message in the console window.
Go to the CoreJavaBookch7NotHelloWorld1
directory. Then, enter the following commands:
javac NotHelloWorld1.java java NotHelloWorld1
Or, if you use an integrated development environment, load the file NotHelloWorld1.java
, then compile and run the program. There should be no warning or error messages during compilation.
When the program runs, it should pop up a window with a silly message.
Here are some troubleshooting hints in case the installation was not successful.
The single, most common problem we encountered with Java is an incorrect PATH
or CLASSPATH
environment variable. Check the following:
The javain
directory must be on PATH
.
The javalibclasses.zip
file and the current directory (that is, the .
directory) must be on CLASSPATH
.
The CoreJavaBook
directory must also be on CLASSPATH
.
Double-check these settings and reboot your computer if you run into trouble.
If you have only 16 Mbytes of memory, you may get “insufficient memory” errors from the Java compiler. In that case, close memory hogs like Netscape and Microsoft Exchange. If you have less than 16 Mbytes of memory, you will probably be unable to compile large programs.
Java is case sensitive. HTML is sometimes case sensitive. DOS is not case sensitive. This caused us no end of grief, especially since Java can give very bizarre error messages when it messes up because of a spelling error. Always check file names, parameter names, class names, keywords, and so on for capitalization.
All example programs in this book use Java 1.1. If your browser supports only Java 1.0, you cannot use it to view the applets that are supplied with this book. You can obtain an updated browser or simply use the applet viewer.
The setup that we described assumes that your platform has a command-line interface and a way for setting environment variables. That is the case for Windows, Unix, and OS/2, but it is not the case for the Macintosh. Read the information supplied by Sun Microsystems or the vendor of your development environment, and modify the installation instructions accordingly.
The CD-ROM contains several hundred files, and some of them are bound to have minor glitches and inconsistencies. We keep a list of frequently asked questions, a list of typographical errors, and bug fixes on the Web. (The main Web page for the book is http://www.horstmann.com/corejava.html.) We very much welcome any reports of typographical errors, example program bugs, and suggestions for improvement.
Before contacting us, please consider the following:
Please check the FAQ (http://www.horstmann.com/corejava/faq.html) and list of bug reports (http://www.horstmann.com/corejava/bugs.html) before mailing us. We get many duplicate queries and bug reports.
Please, no requests for handholding. Many readers have successfully compiled and executed the programs on the CD-ROM. If you have problems, there is an overwhelming likelihood that the problem is on your end, not because of a flaw with the CD-ROM contents. On the other hand, if we goofed, and there is a serious problem with the CD-ROM, then there is an overwhelming chance that hundreds of readers complained to us already and that you will find a resolution on the FAQ.
We want to support and improve the Core Java book and example files, but we cannot help you with problems with the Java compiler, your development environment, or the shareware programs on the CD-ROM. Please contact the product vendor for assistance in those cases.
Finally, when contacting us, please use e-mail only. Please don’t be disappointed if we don’t answer every query or if we don’t get back to you immediately. We do read all e-mail and consider your input to make future editions of this book clearer and more informative.
Exhibit AJava TM Development KitVersion 1.1.xandBDK Version 1.0 CombinedBinary Code License
This binary code license (License) contains rights and restrictions associated with use of the accompanying software and documentation (“Software”). Read the License carefully before installing the Software. By installing the Software you agree to the terms and conditions of this License.
1. Limited License Grant. Sun grants to you (“Licensee”) a non-exclusive, non-transferable limited license to use the Software without fee for evaluation of the Software and for development of JavaTM compatible applets and applications. Licensee may make one archival copy of the Software. Except for the foregoing, Licensee may not re-distribute the Software in whole or in part, either separately or included with a product. Refer to the Java Runtime Environment Version 1.1 binary code license (http://www.javasoft.com/products/JDK/1.1/index.html) for the availability of runtime code which may be distributed with Java compatible applets and applications.
2. Redistribution of Demonstration Files. Sun grants Licensee the right to use, modify and redistribute the Beans example and demonstration code, including the Bean Box (“Demos”), in both source and binary code form provided that (i) Licensee does not utilize the Demos in a manner which is disparaging to Sun; and (ii) Licensee indemnifies and holds Sun harmless from all claims relating to any such use or distribution of the Demos. Such distribution is limited to the source and binary code of the Demos and specifically excludes any rights to modify or distribute any graphical images contained in the Demos.
3. Java Platform Interface. Licensee may not modify the Java Platform Interface (“JPI”), identified as classes contained within the “java” package or any subpackages of the “java” package), by creating additional classes within the JPI or otherwise causing the addition to or modification of the classes in the JPI. In the event that Licensee creates any Java-related API and distributes such API to others for applet or application development, Licensee must promptly publish an accurate specification for such API for free use by all developers of Java-based software.
4. Restrictions Software is confidential copyrighted information of Sun and title to all copies is retained by Sun and/or its licensors. Licensee shall not modify, decompile, disassemble, decrypt, extract, or otherwise reverse engineer Software. Software may not be leased, assigned, or sublicensed, in whole or in part. Software is not designed or intended for use in on-line control of aircraft, air traffic, aircraft navigation or aircraft communications; or in the design, construction, operation or maintenance of any nuclear facility. Licensee warrants that it will not use or redistribute the Software for such purposes.
5. Trademarks and Logos. This License does not authorize Licensee to use any Sun name, trademark or logo. Licensee acknowledges that Sun owns the Java trademark and all Java-related trademarks, logos and icons including the Coffee Cup and Duke (“Java Marks”) and agrees to: (i) comply with the Java Trademark Guidelines at http://java.com/trademarks.html; (ii) not do anything harmful to or inconsistent with Sun's rights in the Java Marks; and (iii) assist Sun in protecting those rights, including assigning to Sun any rights acquired by Licensee in any Java Mark.
6. Disclaimer of Warranty. Software is provided “AS IS”, without a warranty of any kind. ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
7. Limitation of Liability. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE OR ANY THIRD PARTY AS A RESULT OF USING OR DISTRIBUTING SOFTWARE. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
8. Termination. Licensee may terminate this License at any time by destroying all copies of Software. This License will terminate immediately without notice from Sun if Licensee fails to comply with any provision of this License. Upon such termination, Licensee must destroy all copies of Software.
9. Export Regulations. Software, including technical data, is subject to U.S. export control laws, including the U.S. Export Administration Act and its associated regulation, and may be subject to export or import regulations in other countries. Licensee agrees to comply strictly with all such regulations and acknowledges that it has the responsibility to obtain licenses to export, re-export, or import Software. Software may not be downloaded, or otherwise exported or re-exported (i) into, or to a nation or resident of, Cuba, Iran, North Korea, Libya, Sudan, Syria or any country to which the U. S. has embargoed goods; or (ii) to anyone on the U. S. Treasury Department's list of Specially Designated Nations or the U.S. Commerce Department's Table of Denial Orders.
10. Restricted Rights. Use, duplication or disclosure by the United States government is subject to the restrictions as set forth in the Rights in Technical Data and Computer Software Clauses in DFARS 252.227-7013(c)(1)(ii) and FAR 52.227-19(c)(2) as applicable.
11. Governing Law. Any action related to this License will be governed by California law and controlling U. S. federal law. No choice of law rules of any jurisdiction will apply.
12. Severability. If any of the above provisions are held to be in violation of applicable law, void, or unenforceable in any jurisdiction, then such provisions are herewith waived to the extent necessary for the License to be otherwise enforceable in such jurisdiction. However, if in Sun's opinion deletion of any provisions of the License by operation of this paragraph unreasonably compromises the rights or increases the liabilities of Sun or its licensors, Sun reserves the right to terminate the License and refund the fee paid by Licensee, if any, as Licensee's sole and exclusive remedy.
3.138.123.106