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.
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
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.
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:
java.util.zip, 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.)
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.
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-/
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
java.util.zip 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
Just past the halfway mark in the book is a seminal chapter ("Implementing Real-Life Beans") that walks readers through the complete cycle of requirements, design, and construction of a useful, high-quality JavaBean. The chapter takes the time to discuss the requirements for real-world beans, as opposed to including only simple book examples or toys that are cute but add little value to an application. It's astonishing to see an example program in a programming book include a requirements phase, when such a phase is often cut short in the software development world. An architecture for a
RealTimeGraph bean is developed and discussed, and the standard sermon is delivered about the importance of requirements, analysis, and design before coding. After a lengthy description of the solution code, the author even presents a post-mortem on the design, and comes up with some ways to improve the bean.
In the sample bean chapter, visibility (whether a bean can or "wants to" present a visible interface, often a side issue) and localization (also known as internationalization, increasingly not a side issue) are covered through an example.
Reflection and introspection are treated in detail in this book, along with the related rationale for the type changes that accompanied JDK 1.1. The coverage of serialization is sufficient for JavaBeans designers. (RMI developers should look elsewhere for solutions to their thorny serialization problems.) Object replacement during serialization is not covered in this book, but Mastering JavaBeans includes the standard descriptions of how to code serialization and handle object versioning. As always, though, this book goes the extra mile to describe the serialization process in detail, spell out serialization stream formats at the byte level, and point out potential coding problems programmers may encounter.
A single appendix contains a package of utility methods that supports all of the code examples in the book. There is a miniscule glossary, oddly weak in such an otherwise comprehensive work. The index is extremely detailed, and there are references both by concept and by sample class name. Finally, there is a CD-ROM containing all of the source code from the book. Also on the CD-ROM are the JDK 1.1.1 and the BDK 1.1, which should be sufficient for the examples in the book, and for experimentation. The most recent versions of these products, though, should be downloaded from Sun's JavaSoft site (see Resources below for links).
The CD-ROM and glossary actually are a bit of a disappointment, but don't buy this book for the CD-ROM. Buy it because it's hands-down excellent. Throughout the book are "Warnings," "Notes," and "Tips," as well as sidebars on topics related to object-oriented software development, coding style, clarifications of Java features, and high-level design concepts. This book is geared more for the developer who will be developing JavaBeans or for JavaBeans builders than for a beginner just learning or evaluating the technology. But by and large, Mastering JavaBeans is one of the best technology-specific programming books I've ever seen.
Practically anyone who has done serious work with the Unix operating system will know and appreciate the O'Reilly Nutshell handbook series. These books have a well-deserved reputation for presenting arcane and at times extremely poorly-documented systems in a straightforward, accessible manner. O'Reilly now offers a Java series, and Robert Englander's Developing Java Beans (298 pages, O'Reilly and Associates) continues the tradition of quality and clean organization typical of all Nutshell books.
This book also begins with an introduction to the concept of a software component model, but does so in a way that is very Java-oriented. The first sample bean appears on page 5. The first chapter is a clear introduction to the standard JavaBeans concepts.
An easy, organized read
Throughout the book, the text is concise yet easy to understand. The first chapter on events includes a description of the delegation event model, event objects, event sources, standard and multiple-parameter listeners, unicast and multicast event propagation, multithreading issues, and AWT events. Most of these topics have at least some sample code, and all of this is presented in only 29 pages! The chapters that follow cover various types of event adapters and filters, the use of inner classes in event processing (one of their prime applications), and event queuing. The progression from simple, basic concepts to more complex topics is smooth.
Properties of various types (normal, bound, constrained, and so on) are covered in a single chapter with examples. Object serialization is covered well, with examples and explanatory text that follow one another in a logical, easy-to-follow fashion. The serialization chapter is especially valuable because it includes a section on serializing event listeners, an important topic that's easy to overlook (until your code starts throwing exceptions at you, that is.) A short but adequate chapter on the JAR file includes a link to a useful JAR file utility,
moajar. (The link in the book is outdated, but see Resources below for a fresh link.)
There's a short chapter on using the BeanBox that's adequate to get you started. Midway through the book, the initial operational bean functionality is demonstrated by developing a temperature control simulator, constructed of several beans living inside an applet.
Following the chapter on applets is a chapter on introspection. Though the
Introspector class is discussed, as one might expect, the chapter focuses mostly on the
descriptor classes, which a bean uses to communicate with its container, via introspection. The customization and property editor section is thorough yet succinct, and has a section on using property editors to generate Java source code. This is an interesting detail for bean builder developers that is not often covered in other JavaBeans books. A development tool that generates Java source code can ask a configured bean for the source code that would initialize the bean to its current state, and then dump Java code that initializes and interconnects beans (instead of simply creating a JAR file containing serialized beans).
Unique info: The ActiveX Bridge
Of the three books reviewed here, Developing JavaBeans is the only one that addresses the use of the ActiveX Bridge, Sun's technology for wrapping JavaBeans as ActiveX components. An actual example of how to use the Bridge is provided, and this chapter alone makes the book worth purchasing for anyone who wants a tutorial introduction to the Bridge. The example demonstrates how to wrap one of the example beans from the book as an ActiveX control, and then how to use that control in a Visual Basic program.
The book ends with two appendices, one on what Sun's JavaSoft division has unfortunately decided to call "Design Patterns" (which are actually naming conventions), and another with short but adequate annotated descriptions of the classes and interfaces in
java.beans. The index is usable and complete. The endnotes also include a colophon, an elegant addition that appears in all Nutshell books.
A code caveat
Apparently, many of the code samples in the book itself are incorrect. O'Reilly has acknowledged and fixed the problem, and the corrected sample code is available at the publisher's Web site. See the Resources section below for a link to the new sample code.
Because this book is terser than many others, the treatment of concepts and sample code isn't as extensive as in other books. But if you're a quick study and want a book that cuts to the chase, Developing JavaBeans is an excellent choice. This book also makes a great resource for the programmer whose motto is, I either know how to do it, or I know where to find it.
I can heartily recommend all of the books reviewed in this column, with each book showing its greatest strength in the areas I've indicated. Mastering JavaBeans is the most complete and in-depth work, JavaBeans is excellent for a tutorial introduction, and Developing JavaBeans is great for programmers who want just the facts. Truly, though, any one of these books will serve you well for any of these purposes.
Learn more about this topic
Pointers to books reviewed in the column
- Elliotte Rusty Harold's book JavaBeans is available at Computer Literacy http://www.clbooks.com/sqlnut/SP/search/gtsumt?source=javaworld&isbn=0764580523
- The publisher of Harold's book, IDG Books, has a Web site; a sample chapter from the book is available http://www.idgbooks.com/cgi-bin/db/fill_out_template.pl?idgbook:0-7645-8052-3:book-idg::uidg217
- Harold has his own site for this book, including some sample text and the sample code from the book http://sunsite.unc.edu/javafaq/books/beans/
- Laurence Vanhelsuwé's Mastering JavaBeans is available at Computer Literacy http://www.clbooks.com/sqlnut/SP/search/gtsumt?source=javaworld&isbn=0782120970
- Sybex, the publisher of Vanhelsuwé's book, has its own site http://www.sybex.com/cgi-bin/bookpg.pl?2097back.html
- Robert Englander's Developing JavaBeans is available at Computer Literacy http://www.clbooks.com/sqlnut/SP/search/gtsumt?source=javaworld&isbn=1565922891
- The publisher's of this book, O'Reilly, has its own site http://www.oreilly.com/catalog/javabeans/
Other books and resources by these authors
- Information about Elliotte Rusty Harold's other works, plus many Java links, and daily Java news appears at the popular Café Au Lait Web site at http://sunsite.unc.edu/javafaq
- Also featured at this Café Au Lait Web site is a large list of books that Harold recommends (as well as those he doesn't recommend) http://sunsite.unc.edu/javafaq/books.html
- Harold's list of books is not as comprehensive as JavaWorld's Java Book Catalog http://www.javaworld.com/javaworld/books/jw-books-index.html
- Vanhelsuwé is also the lead author of Mastering Java http://www.clbooks.com/sqlnut/SP/search/gtsumt?source=javaworld&isbn=0782119352
- Because some of the source code from Developing Java Beans is incorrect, it may save you a lot of time to download it via FTP. (The "Errata"link on the publisher's page describes precisely what was fixed.) Get the corrected sample code for this book at ftp://ftp.ora.com/pub/examples/java/javabeans/
moajarutility mentioned in this article's discussion of Developing Java Beans book can be found at http://www.camb.opengroup.org/RI/java/moa/moajar/index.html
- JavaWorld's topical index offers links to all our published reviews http://www.javaworld.com/common/jw-ti-bookreviews.html