Java Reference
In-Depth Information
For example, suppose that you need to develop a program that allows cus-
tomers to purchase items online. You could use an existing bean that searches
the database for inventory, a bean that handles credit card payments, and a
collection of beans to create the GUI. You could write new beans for creating a
shopping cart and enabling users to log in. Using existing beans accelerates
development time, and writing new beans allows them to easily be used in
other applications.
A JavaBean has three basic components:
Properties. The properties of a bean describe characteristics of the bean
that can be viewed and can be changed by other beans.
Methods. The methods of a bean are the behaviors of the bean that can
be invoked by other beans.
Events. A bean can be the source of an event. Events provide the mecha-
nism that enables beans to communicate with each other.
Each of these components of a JavaBean is determined by the public meth-
ods that are defined within a bean's class. The JavaBeans specification defines
how methods are named and which methods need to appear in a class to
denote the bean's properties and events.
Classroom Q & A
Q: How do you create a JavaBean?
A: A JavaBean is simply a class. What makes the class a JavaBean are
the methods you add to the class. The JavaBeans specification
defines how methods are named to denote properties and events
of a bean. In this chapter, I will discuss the JavaBeans specification
for naming the methods of a bean class.
Q: So to write a bean, all I need to do is follow a certain naming con-
vention for methods in a class?
A: Well, there is more to it than that. A JavaBean is not just a class
describing an object. It is a software component that can be
plugged into an application and used by other components, and it
has properties that other beans can view and change. It fires
events to communicate with other components.
Q: What if I have an existing class that I want to make into a Java-
Bean, but I didn't follow the specification for naming methods?
Search WWH ::




Custom Search