JavaBeans book review

We picked three winners -- now let's see how they stack up

There's a growing stack of JavaBeans books on the market. Their quality ranges from excellent to execrable, and it's hard to know which book will meet your needs without buying one. This month, I'll help you out by taking a detailed look at three JavaBeans books. I chose these books more or less at random, and I got lucky: they're all excellent books.

Rather than comb through these well-written volumes looking for things to pick apart, this review will focus on their overall content. I'll be looking at how easy it is to use each book as a tutorial and as a reference, general readability, and those particular features of each book that add value. Occasional pitfalls and omissions crop up, and I'll clue you in on those as well.

The major difference among the books is not in quality (which is uniformly high), but in content, which goes beyond the basic JavaBeans model to educate the reader about the broader context of Java development.

JavaBeans by Elliotte Rusty Harold

Elliotte Rusty Harold is a prolific writer, and has several Java-related books to his name. (See Resources for a list of his books.) His newest effort, JavaBeans: Developing Component Software in Java (355 pages, IDG Books), is an accessible and entertaining introduction to JavaBeans technology. That this book was written in a bit more than four months, frankly, is astounding: There's a lot of valuable material here, and the book is well-written.

Section 1: Introducing JavaBeans

The book opens with a high-level look at component software, introducing the reader to the general concepts involved in using software components, and describing some of their benefits. The first chapter, "Introducing JavaBeans," also covers definitions of such terms as persistence, introspection, event handling, and distributed computing. This chapter provides an explanation of other component models, including CORBA, Visual Basic VBX files, and an amusing critique of Microsoft's entrant into the component technology world, ActiveX. This author certainly makes his views clear on the quality of what's coming out of Redmond!

JavaBeans continues with short discussions of the key technologies specific to JavaBeans technology, including persistence, packaging (JAR files), events, security, and networking. An extended introduction to the BeanBox demonstrates these technologies from the "outside," showing how they work in the BeanBox. The BeanBox is followed by a very simple tutorial example -- creating a JavaBean from scratch. This demonstrates how the simpler features of JavaBeans work, discussing some of the programming issues that inevitably arise.

Section 2: Key Technologies

JavaBeans' second section, "Key Technologies," expands on the basic concepts found in the first part of the book. This section includes code samples and points out potential pitfalls, confusions, and flaws in the Java API. (Programmers can be hard to please.)

"Reading Signatures at Runtime," a chapter on using java.lang.reflect (the Java "reflection" mechanism), describes how builder tools figure out a class's methods, event sets, fields, and modifiers, and describes how to use reflection in a Java program. Because most JavaBeans developers will seldom, if ever, need to use reflection, it may have been more logical to put this section toward the end of the book, perhaps even as an appendix. The author does explicitly state, however, that he believes developers should always know more than they have to know, and he delivers on this premise by providing good technology backgrounders like the reflection chapter.

The "Key Technologies" section also includes a chapter on events, with the requisite introduction to the delegation event model introduced with JDK 1.1. The chapter on events is complete enough for a beginner, although it does not address multicast/unicast issues, nor does it discuss threading in this context. It's a great presentation of events, but you'll have to look elsewhere for these topics. The event chapter does contain copious figures spelling out interfaces, class constants, and so on. Large quantities of text copied from standard documentation can be distracting and/or overwhelming to beginners, but this may prove a useful reference for more experienced developers. A section on basic and customized serialization covers the bases with discussions and examples of default and more advanced serialization topics.

Section 3: The JavaBeans Architecture

The third section of JavaBeans, "The JavaBeans Architecture," describes how beans interact with the builder tools used to create and manipulate them. This information is crucial for creating JavaBeans with user-friendly and programmer-friendly interfaces. It also clarifies how existing Java class files, which very likely may not adhere to JavaBeans naming conventions, can be extended to become JavaBeans without extensive rewriting. This section includes a chapter on BeanInfo and Introspector and on writing and using Customizer. This book's chapter on properties appears oddly late (Chapter 9), given that properties are such a basic JavaBeans concept. On the other hand, properties and their naming conventions closely relate to builder tools, so the placement in this section makes some sense.

The final chapter of JavaBeans provides a full-on design and development of a real, useful JavaBean, including concepts from every chapter in the book. One nice touch is the inclusion of an Image bean that, though trivial, resolves an issue common to beginning JavaBeans developers -- one that presents a stumbling block. (The class java.awt.Image does not implement Serializable, therefore a bean can't depend on default serialization for any Image it might contain.)

Last, but not least: Appendices and notes

Appendices in the JavaBeans book include: a useful "QuickRef," an annotated description of the signatures of every method in package java.beans; "Additional Resources" pointing users to JavaSoft's Web site, Gamelan, JavaWorld, and newsgroups, listservices, and the author's e-mail address. Harold also created and maintains Café Au Lait, one of the most popular Java sites on the Web. (See Resources below for a link.) A companion CD-ROM includes all of the examples from the book (of course), the Sun JDK (1.1.40 for Solaris and Windows 95/NT), the September '97 release of the Beans Developer's Kit (BDK, already outdated but still useful for experimentation), demos for several commercial beans packages, and a 45-day evaluation copy of Kawa, a beans-aware Java Integrated Development Environment (IDE). The book also includes a glossary and an ample index.

Scattered throughout the text are "Notes" -- usually in the form of tips on writing class files or "gotchas" with Java or beans. Some of these notes are complaints about Sun or expressions of the author's personal preferences (exhortations to make "freeware" beans commercially available, for example), which you may find either helpful (as advice from a noted expert) or annoying (as advice), depending on how you feel about such things. Personally, I think his comments are right on the mark.

A few final comments. The book is humorous in places, which always makes technical reading more palatable. There are quite a few figures containing code symbols and method signatures, but very few explanatory diagrams. In sum, this is an excellent book for a developer interested in learning about JavaBeans from the ground up.

Mastering JavaBeans by Laurence Vanhelsuwé

This book wins the prize for depth, breadth, and thickness. Weighing in at precisely 800 pages (not including the introduction), Mastering JavaBeans is an excellent reference for JavaBeans programmers. Such massive tomes are commonly little more than reprints of poorly-written documentation, inflated sample code, and pages of source code better read online. Not so with this book. Mastering JavaBeans is enormous because it lives up to its title. It covers packages, classes, and concepts that other JavaBeans books don't even touch on:, for example, in the chapter on JAR files; design pointers, such as what to do when you find that you are cutting-and-pasting yourself into unmaintainability; and a lengthy (and much-needed) discussion of the use and limitations of java.awt.EventQueue. Last but not least, this book has the distinction of being the only book (to my knowledge) bearing a personal dedication to a hypertrophic rodent prodigy. (Don't worry if you don't understand this. I don't understand it either.)

Introductory material

Mastering JavaBeans starts with a historical perspective of software development, describing why component software solves problems that have haunted software development since the Paleolithic era, or at least since 1945. This discussion sets the stage for a description of why Java and JavaBeans solves most, if not all, of the world's problems. There is also an excellent explanation of what a software component is and why software components are a cool concept, before diving into the specifics of Java class files. Anyone looking for a general introduction to component technology in a few pages will have to do some searching to find a better resource.

JavaBeans technology is first introduced in the second chapter, with an introduction to the BeanBox and descriptions of each sample bean in the BDK distribution.

JavaBeans in-depth

An entire chapter is devoted to the Java 1.1 delegation event model. This chapter begins by explaining the inadequacies of the JDK 1.0 approach, describes the 1.1 solution conceptually, and then presents the Java API that implements the solution. It then describes unicast and multicast event sources, and provides two examples. As a bonus, this chapter ends with the aforementioned in-depth description of a design problem in the 1.1 AWT that can lead to deadlock. For the programmer with a class file that's behaving in a way she doesn't understand, this sort of information can be a lifesaver.

The chapter on bean properties is equally ample. The standard descriptions of property types (boolean, integer, class, and so on) and categories (bound, constrained) are covered with sample code. This chapter also discusses per-property change listeners, which cut down on inefficient event traffic in an application. There's also a discussion of properties and event listeners in a multithreaded environment, a topic usually glossed over or completely ignored in other texts. Bugs related to multithread race conditions can be very difficult to solve, as often they're not consistently repeatable. The properties and multithreading discussion walks the reader through an example of the kind of problem that can arise when a bean is not thread-aware, and then discusses the solution.

In addition to the general topic of the post-1.1 event model, there's a chapter on how beans are written to handle and fire events (in particular, subclasses of java.awt.event). This chapter actually develops and explains the implementation of three software tools (an ActionEvent-activated bean that lights up when an event occurs, a key-/mouse-/ItemEvent-to-ActionEvent translator bean, and a generic AWTEvent monitor) that can be used to debug applications that pass events. Although the text is clear and the examples are interesting, this section of the book might lose novice beans developers because it's quite in-depth. To an experienced developer struggling with complex event relationships, though, these tools are both illustrative and extremely useful.

Most beans books relegate the JAR file under the subheading "packaging,", dedicate a few lonely pages and an example to the topic, and then abandon it for more interesting material. This book, though, devotes a whole chapter to the JAR file, its format, and the package used to implement the JAR file interface. This chapter even delves into the esoterica of the CRC mechanism used to error-check ZIP file streams just in case you decide you have too much free time and need to know everything about JAR files. Of course, the chapter also introduces a tool (written in Java) that can be used to summarize and debug JAR files. As a reader, you may not be interested in this level of detail. But the details are there if you ever need them.

The chapter on BeanInfo, bean descriptors of various sorts, and the Customizer interface is as thorough as the rest of the book, at least touching on every possible topic. Every detail of implementing these classes and interfaces is covered with sample code and discussion. The chapter develops a complete customizer called PlugNPray (my favorite new term). A chapter is also devoted to the design and construction of customized property editors, which users employ in property sheets and customizers to edit properties of an arbitrary class. No fewer than four custom property editors are developed in this chapter, along with a bean that uses one of these editors in a small application. Each example has something to add to the description, and they are arranged in order of increasing complexity.

JavaBeans in action

1 2 Page 1
Page 1 of 2