The JavaBeans architecture is Java's primary mechanism for supporting component programming in client programs. (Other options are available for component programming on the server side.) The intention is to allow developers to build larger than class entities that can later be reused to build specialized applications within a visual programming environment.
JavaBeans include six main features:
- Properties
- Methods
- Events
- Persistence/serialization
- Introspection/reflection
- Custimization
This discussion of JavaBeans is oriented around several examples:
Temperature and Meter Beans
The emphasis in this example is on the basic architecture of beans and the process of developing beans and interconnecting them using a development environment -- in this case, VisualCafe. Two beans are shown -- a temperature bean and a meter bean. The first allows the user to raise and lower a "temperature" property; the second displays the current value of the temperature.
Two versions of the beans illustrate the two different ways of interconnecting beans: through conventional events and listener registration mechanisms and through bound properties supported by specialized mechanisms included in the java.beans package.
Flow Simulation
This example places more emphasis on the beans themselves. It includes container and pipe beans that allow the user to construct various configurations in which a "liquid" flows from one container to another through one or more pipes.
The discussion addresses the design process, including identifying an initial set of functions, designing the structure of supporting classes, and developing the subclasses to implement the actual container and pipe beans. The example also illustrates the use of threads in beans.
WWW Browser
This discussion is based on Sun's HotJava HTML Component, a set of beans that implement most of the function found in Sun's HotJava browser. By packaging that code as a set of beans, Sun ennobles developers to build specialized browsers and other programs in which HTML data needs to be rendered.