Beans are Java™ classes
that adhere to specific conventions regarding property and event interface
definitions. By conforming to the conventions, you can turn almost
any existing programming component or Java class into a bean.
JavaBeans (thereafter
referred to as beans) are reusable software components that are written
in the Java programming language
and can be manipulated by using beans-aware builder tools. Because
the beans are reusable, you can use them to construct more complex
components, build new applications, or add functionality to existing
applications. You can interact with beans visually, by using a builder,
or manually, by calling the beans methods from a program.
Beans define a design-time interface that allows application builder
tools to query components to determine the kinds of properties these
components define and the kinds of events they generate (or to which
they respond). You do not need to use special introspection and construction
tools when working with beans. The pattern signatures are defined
and can be easily recognized and understood by visual inspection.
Beans have the following characteristics:
- Introspection
- Introspection is the process by which a builder tool determines
and analyzes how a bean works at design and run time. Because the
beans are coded with predefined patterns for their method signatures
and class definitions, tools that recognize these patterns can "look
inside" a bean to determine its properties and behavior. Each bean
has a related bean information class, which provides property, method,
and event information about the bean itself. Each bean information
class implements a BeanInfo interface, which
explicitly lists the bean features that are exposed to application
builder tools.
- Properties
- Properties control the appearance and behavior of a bean. Builder
tools perform introspection on a bean to discover its properties and
to expose those properties for manipulation, which allows you to change
the property of a bean at design time.
- Customization
- The exposed properties of a bean can be customized at design time.
Customization allows you to alter the appearance and behavior of a
bean. Beans support customization by using property editors or by
using special, sophisticated bean customizers.
- Events
- Beans use the Java event
model to communicate with other beans. Beans can fire events. When
a bean fires an event it is considered a source bean. A bean can also
receive an event, in which case it is considered a listener bean.
A listener bean registers its interest in the event with the source
bean. Builder tools use introspection to determine those events that
a bean sends and those events that it receives.
- Persistence
- Beans use Java object serialization,
by implementing the java.io.Serializable interface, to save and restore
states that might have changed as a result of customization. For example,
when an application customizes a bean in an application builder, the
state is saved so that any changed properties can be restored at a
later time.
- Methods
- All bean methods are identical to methods of other Java classes. Bean methods can be called by
other beans or through scripting languages.