Java Reference
In-Depth Information
Preparing a Class as a JavaBean
Problem
You have a class that you would like to install as a JavaBean.
Solution
Make sure the class meets the JavaBeans requirements; create a JAR file containing the
class, a manifest, and any ancillary entries.
Discussion
Several kinds of Java components are called either Beans or JavaBeans:
▪ Visual components for use in GUI builders, as discussed in this chapter.
▪ Plain Old Java Objects (POJOs), or components meant for reuse.
▪ Java Enterprise has “Enterprise JavaBeans” (EJBs), “JSP JavaBeans,” “JSF managed
Beans,” and “CDI Beans,” containing features for building enterprise-scale applications.
Creating and using Java EE components is more involved than regular JavaBeans and
would take us very far afield, so they are not covered in this topic. When you need to
learn about enterprise functionality, turn to
Java EE 7 Essentials
by Arun Gupta
(O'Reilly).
▪ The
Spring Framework
also uses the term “Beans” for the objects it manages.
What all these types of beans have in common are certain naming paradigms. All public
properties should be accessible by get/set accessor methods. For a given property
Prop
of
type
Type
, the following two methods should exist (note the capitalization):
public Type getProp( );
public void setProp(Type)
The one commonly permitted variance to this pattern is that, for
boolean
or
Boolean
argu-
ments, the “get” method is usually called
isProp()
rather than
getProp()
.