The Codesmith's Library - The Java Handbook
Written by Carsten Whimster
In The Codesmith's Library, I focus on development books and materials. I write this column from the point of view of an intermediate programmer. Pick up whichever book strikes your fancy, and join the growing group of people following our programming columns.
Please send me your comments and thoughts so that I can make this column what you want it to be. I read and respond to all mail.
The Java Handbook
This book is a little different than most Java books, in that it was written by an insider, and has a long chapter with more or less the full story behind Java, including before it became a language product.
Part I: Java Language 1. The Java Revolution 2. Object-Oriented Fundamentals 3. Java Language Introduction 4. Types 5. Operators 6. Flow Control 7. Classes 8. Packages and Interfaces Part II: Java Classes 9. String Handling 10. Exception Handling 11. Threads and Synchronization 12. Utilities 13. Input/Output 14. Networking 15. Applets 16. Abstract Window Toolkit 17. Imaging Part III: Java Applets 18. Impression Applet 19. DynaDraw 20. Magnet Poetry Appendix A: Getting the Java Development Kit Epilogue
Chapter one is a brief introduction to Java, and what Java is good at. It explains much of the philosophy of Java, and covers all the buzz-words too.
The next chapter covers the object-oriented programming paradigm. The basic concepts are explained, with easy-to-understand examples. Then the philosophy of C++ is covered, quickly followed by an outline of where Java is better than C++. To be fair, Naughton even mentions that if you need great performance, and access to a lot of system-specific stuff, then C++ may be a better language for you.
In the third chapter, we meet Java in the flesh (Java in the hut?). Some very simple examples are covered in detail, with great explanations along the way of everything you could imagine. Then we move to a description of keywords and other language features. Finally, a complete Java program is covered for you to try.
Chapter four gets more in-depth. Types are the subject, and the depth is great. The basic object-oriented-ness of Java's types is explained. Some C-isms are covered, ie. "how to do this in Java"-type things. More compex types are also covered.
Operators are next on the agenda, in chapter five. What can I say; he covers them too :) This includes binary operators, arithmetic operators, boolean operators, and so on. Note that in Java there is an enforced distinction between these types, unlike in C.
Chapter six is a little longer. Flow control is covered, ie. ifs, buts (just kidding), elses, switch, return, while, do-while, for, comma, continue and a very cursory look at exceptions.
Chapter seven starts to get beyond the rudiments, and into the raison-d'etre of Java, classes. Object references, new, garbage collection, the dot operator, declarations, instance variables, the this "pointer" (reference in Java), constructors, overloading, ingeritance, super, dynamic method dispatch, final, fianlize, static, and abstract classes are all covered quickly.
For programming in the large, Java has several features. Packages and interfaces are introduced in chapter eight. These features probably won't appeal to utility programmers and novices, but for large projects, and organization, these are a godsend for experienced programmers. The various kinds of access protection are covered, as well as when and how to declare and use interfaces.
That concludes Part I, the introduction to the language features. Part II moves on to actual programs, and how to use features efficiently.
We start with a look at string handling in chapter nine. Strings are quite unusual in Java in that there are two basic types: read-only and read-write, called String and StringBuffer, respectively. This is likely to catch a lot of people off-guard, and cause all kinds of problems, but not if they read this book first. Various string issues appear, including operator precedence, conversion, characters, and so on.
Chapter ten covers a favorite topic of mine, exception handling. Exceptions have to be one of the greatest features ever. They can potentially make code so much more understandable and robust that it is a minor miracle that all languages don't have them. C++ kinda has them, but not as cleanly as Java and Modula-3. Java's exceptions actually look a lot like C++'s, but there are differences under the surface.
Threads are always a hard topic. Understanding them shouldn't be too bad, but they are so tricky to use, when there are shared resources. This gives rise to the coincident topic of synchronization. Java seems to have a very good selection of primitives to handle these. One thing is for sure: Java's threads are better than OS/2 threads in C or C++, conceptually. They are just much cleaner.
Chapter twelve is called Utilities, and is a partial description of "an ad-hoc collection of utility classes used throughout the other core Java packages". It hits a little on everything, but has no time for real depth. Presumably there will be a book dedicated to this topic some day.
Input and output is the topic of chapter 13. The usual assortment of sample programs accompanies this, and the many different types of streams are explained.
Networking is THE buzz-word these days, and Java is in the middle of the fray. Microsoft is trying to compete with Active-X, but hopefully most companies have the brains to realize that it is incredibly poorly thought-through compared to a from-scratch solution like Java. I really don't want to have to program in Active-X one day, if Java dies. Networking is one of the core ideas in Java. It permeates many of the classes, and there is API-level support for most things one would want to do. Sockets, datagrams, you name it, it's probably there. The sample program is a (pathetically) simple HTTP server. The fact that the code is incredibly short really highlights Java's focus on networking.
Applets are the talk of the town, even though they ultimately may not be as important as regular Java apps. Chapter 15 introduces applets, complete with yucky screenshots from Win95. Some basic techniques are covered, but really this chapter is 70% reference.
The AWT, or Abstract Windows Toolkit, forms the basis of chapter sixteen. The neat feature of this is that the same interface runs on Win95, NT, OS/2, Mac, UNIX, and anything else with a Java interpreter. To do this, some odd things are requied. Once you get used to the idea of self-arranging windows of "things", you are on the way to grasping this subject.
The imaging discussed in chapter seventeen relates to several built-in graphics classes. There is built-in support for most of the important graphics formats on the web. JPG and GIF were the only ones originally, but I would be very surprised if PNG is not there now. Many common functions exist in Java to handle graphics, so we should see some real graphic viewers out there soon.
Part III has some cool Java applets. I will just briefly mention them here. Each of them is given a detailed explanation, and several screenshots. Each of them is more of a demo than anything else, but they are quite cool. The Impression applet takes an image, and applies various "impressionistic" effects to it. DynaDraw is a drawing program with some built-in physics to emulate real weight and so on. The Magnet Poetry applet is a series of small magnet-like words on pieces that can be arranged, scrambled, and what-have-you.
The appendix shows you how to get Java, although for OS/2 users, you have to go to IBM instead of to Sun. The epilogue is the story of Java, from pre-Java to product.
This book is quite a good one. It is easy to read and understand, and covers the material well, if a touch lightly in places. It was written by one of the original team members who developed and conceived Java, and as such has some insight that you probably won't see in many other books. I give it an A. A straight-forward, good tutorial on Java.
The Java Handbook, Patrick Naughton
Our Bookstore has reviews and links to Amazon for all books we have reviewed in the past, as well as several books waiting to be reviewed, and others which we recommend.