John is a member of the computer science staff at Sam Houston State University in Huntsville, Texas. He can be contacted at csc_jhm@shsu.edu.
Last year's book-publishing love affair with the Internet has already morphed into this year's doting on Java, the programming environment from Sun Microsystems. Although there are numerous Java-related books in the works, Hooked on Java, by Java development team members Arthur van Hoff, Sami Shaio, and Orca Starbuck, is one of the first. For $29.95 you get the book and a CD-ROM containing documentation, sample applets, and development tools in both Sun Solaris 2.x, Windows 95, and Windows NT format. Both a Java compiler and an applet viewer are included and neither an Internet connection nor a browser is needed to explore the language or the sample applets on the CD. You do, however, need Netscape Navigator 2.0 to run the Java-powered Web pages.
The book, which consists of six chapters and numerous appendices, is intended for anyone involved with the creation of Web pages and/or interested in learning the basics of Java applets. Chapters 3 and 4 constitute a "cookbook" for integrating the applets into Web pages. All the applets covered are included on the CD along with an example Web page using the applet. You should be familiar with HTML, but progression beyond the HTML bunny slopes will be needed to creatively apply much of the information. Chapters 5 and 6 cover basic Java syntax and building a Java applet from scratch. Here, the primitive state of Java and the lack of development tools become apparent. The authors' statement in chapter 5 (repeated in chapter 6) that "You should know a little about programming to get the most out of this chapter" is an understatement to say the least.
In the cookbook section, the authors thoroughly describe the applets and how to incorporate them into Web pages. The reading is easy and the discussion on the Applet tag in chapter 3 is excellent. After a few examples, however, you'll likely want to skip to the CD and run the applets from the menu and use this part of the text for reference. In looking over the Applet tag examples, I did notice that quotes are used inconsistently. In one instance, the code filename is quoted, in the next it isn't. Knowing that quotes are only required if a string contains a blank is helpful when you are getting started. Rather than cutting and pasting from the examples, I wrote my own entry from the Applet Tag Definition in Appendix G. Nothing in the definition indicated to me that "=" signs are needed, but they are and the examples have them. DOS readers would also benefit from a discussion about the use of "\" versus "/" in paths.
The overview of the Java language in chapter 5 is good, but it is C code. I stuck with the green slopes in C code and I found it easy going. Programmers who aren't C coders may need a reference, but the level is about right. The assertion that data types are platform independent left me wondering how I missed the signing of the peace treaty in the Big Endian/Little Endian holy war. There is an unfortunate typo in the discussion of control-flow statements. It probably won't be a problem because most programmers will probably just look at the syntax and skip the verbiage. The coverage is adequate for its intended use and the more adventurous can download the Java Language reference from the Internet or print it from the JAVASPEC.PS file in the Psfiles.zip archive.
Chapter 6 is the programming guide for creating your own applets. Sample code (which you can cut and paste into your own applet) is included on the CD and is discussed in this chapter. Documentation for the Java Developers Kit has to be downloaded from the Internet. The Java programming page on the CD is blank, so the hardcopy chapter and appendices are all there is. DOS users will be frustrated by some of the compiler's idiosyncrasies. For example, the compiler is case sensitive in file names entered on the command line. Attempting to compile an applet with "javac uiapplet.java" instead of "javac UIApplet.java" will cause the compiler to bomb with the message "Warning! Public class UIApplet must be defined in a file 'UIApplet.java'." This is definitely not what a DOS-oriented person would expect, and some warning is needed.
The applets on the CD are obviously intended to be a dazzling show of flashy animation to get you "hooked on Java." Once you get it set up, the applets perform pretty much as advertised. Some are incomplete and the animation is slow. Most are merely frustrating--the ballistic simulation is so slow that it is effectively unusable on my DX2-66. The tortuously slow antics of the "Duke" mascot make him appear more as the personification of an abscessed tooth than the jovial mascot he's supposed to be. It is at least implied in the book that the authors in their positions at Sun are responsible for the current incarnation of Java. Thus, while it is not totally correct to say that the performance problem is beyond their control, I think it is fair to say that applets are likely to be more impressive and addictive on a Sun workstation than on a typical PC.
The Readme.txt file in the Win95 directory of the CD correctly states that you can't run the Windows 95 Java Development Kit from the CD. It also states that you can run the Web pages from the CD. However, the \Win95\index.html file does not exist and the subdirectories in the Solaris directory have been compressed into zip files in the Win95 directory. To run anything you must first install the files on your hard disk using an unzip program that can handle long file names. I first unzipped it using OS/2 and copied the files to Win95 over my peer network. Since then, I have acquired WinZip 6 and reinstalled everything. It works fine.
During the unzip of docs.zip you will encounter a duplicate file name. If you open the docs archive in the WinZip window you will see java.awt.image.html and java.awt.Image.html. If you have Navigator 2.0 installed you can view any of the HTML pages by dragging it and dropping it on the Netscape icon. I should say you can view any of them except the java .awt.Image.html. Since the Windows 95 file system is not case sensitive it always finds the first one. java.awt.image.html documents the package java.awt.image, while java.awt.Image.html documents the class java.awt.image. No matter what you do it will be wrong. I used a different name for the first file. It ends up as an orphan, but it is accessible if you ever need it and can remember what you named it. Once installed, all the applets can be run in Navigator 2.0 by loading one of the menu files /hooked/book/building.html or /hooked/book/cool-applets.html and selecting the desired applet.
Only two applets had a problem I couldn't correct. UIApplet 2 and UIApplet 3 both use a setBackground() and a setForeground() method to set colors. I could set any color I wished and recompile the applet, but it always displayed black on gray. This was true whether I used the Applet viewer or Netscape.
There also is a problem with the align attribute in the Applet tag. This shows up in both the clock and the image loop Web pages. If the align appears in the Web page when it is loaded, the applet will not run. You won't see the clock ticking or "Duke" waving at you. If you leave the align attribute out, both applets will run, but they display in the wrong place on the page and the text does not wrap around the applet. Surprisingly, if you edit the page while it is active and add the align-right attribute, then click reload, the applet works as it should. I tried loading the pages both from local files and from an OS/2 http server, and got the same results. The Netscape browser I am using is a beta version and the problem may be resolved in the final release.
The documentation for the Java classes and packages is included on the CD in hypertext form. A search tool is mentioned, but I could never locate it. Consequently, finding a method is hit or miss if you don't know what class or package it is in. I tried to look up the setForeground() and setBackground() methods and essentially had to scan all of the class methods. When you do locate it, you wonder why you bothered because it is typical UNIX man-page jargon. If you prefer hard copy, you can print it from the Postscript files.
Whether you think Java is a curse or a blessing is irrelevant. Java is a fact to be dealt with. If you need to get acquainted with it, I recommend Hooked On Java as a good starting point, particularly if you don't have an Internet connection. Like most things associated with Java, Hooked On Java is not quite finished, but I thought it was a good buy when I bought it and I still do.
Hooked On Java
Arthur van Hoff, Sami Shaio, and Orca Starbuck
Addison-Wesley Publishing, 1996
181 pp., $29.95
ISBN 0-201-48837-X