JavaBeans and Java Builder Tools
The JavaBeans technology is a significant extension and enhancement of the Java language that makes it possible for programmers to rapidly build applications by assembling objects and testing them during design time. This makes reuse of the software more productive. This article demonstrates how to use JavaBeans in Java builder tools such as JBuilder and Forte for rapid application development.
JavaBeans is a software component architecture that extends the power of the Java language to enable well-formed objects to be manipulated visually in a builder tool such as Forte during design time. Such well-formed objects are referred to as Java beans or simply beans. The classes that define the beans, referred to as JavaBeans components, bean components, or simply components, must conform to the JavaBeans component model with the following:
A bean must be a public class.
A bean component must have a public default constructor (one that takes no arguments), although it can have other constructors, if needed. For example, a bean named MyBean either must have a constructor with the signature public MyBean(); or must have no constructor if its superclass has a default constructor.
A bean component must implement the Serializable interface to ensure a persistent state. JavaBeans can be used in a wide variety of tools, such as Lotus, Delphi, MS Visual Basic, and MS Word. Bean persistence may be required when JavaBeans are used in other tools. Some tools are needed to save the beans and restore them later. Bean persistence ensures that the tools can reconstruct the properties and consistent behaviors of the bean to the state in which it was saved.
A bean component usually has properties with public accessor methods that enable them to be seen and updated visually by a builder tool. To enable the properties to be manipulated, the accessor methods must conform to the naming patterns or must be specified explicitly, using the BeanInfo interface. According to the accessor method-naming pattern, the method must be named get<PropertyName>() for getting the property value and set<PropertyName>() for setting the property value.
A bean component may have events with public registration methods that enable it to add and remove listeners. If the bean plays a role as the source of events, it must provide registration methods.
The first three requirements must be observed by all beans and, therefore, are referred to as minimum JavaBeans component requirements. The last two requirements are dependent on implementations. It is possible to write a bean without accessor methods and event-registration methods.
A JavaBeans component is a special kind of Java class. The relationship of a JavaBeans component and a Java class is illustrated in Figure 1.
Figure 1 A JavaBeans component is a serializable public class with a default constructor.