A standard for Java componentware. It functions much like Microsoft’s
Windows-specific VBX Visual Basic pluggable components. The JavaBeans APIs allow
ISVs to develop reusable software components that end-users can then hook
together using visual application builder tools, such as Inprise’s
JBuilder, IBM’s Visual Age, SunSoft’s Java Workshop and Symantec’s
Visual Café. For example, Visual Café Pro has already created many
smart components to give Delphi-like abilities to crank out SQL database
applications. JavaBeans have persistence (with serialised customised objects
stored in *.ser pickle files), properties, events and methods that are exposed
to the GUI designer. They also support "introspection" so that GUI
builder tools can examine them to figure out what properties and methods they
support.
Writing a Bean is easy.
- They require a public parameterless default constructor.
- Beans must be totally freestanding. They can’t presume anything has been
done for them ahead of time. If they need it, they have to create it or fake it
for themselves. For example, they can’t presume some static call has been
done to set up a Window for them to display error messages. Beans are like
little reptiles that must be able to fend for themselves the moment they hatch (are
constructed).
- A bean has no special interface to implement, just the dummy Serializable.
There is a formal
- Just use the standard getXXX, setXXX naming conventions for your properties and
make public the ones you want to expose. You can hide some of the public
properties later in your BeanInfo to give you the
Delphi-like distinction between public and published.
- String properties should be initialised to "" or some value rather
than null.
- Provide a BeanInfo class to describe the properties. BeanInfo
classes can get pretty elaborate, but writing a minimal one is very simple. I
have provided some sample source under BeanInfo. It
theory, you can have a bean without a BeanInfo, but
it best to write one, even if just to provide an icon.
Usually beans are bundled up with their corresponding BeanInfo
classes into jar files.
JavaBeans have a persistence mechanism similar to serialization, but uses a
fluffy XML format and the PersistenceDelegate class.
Many companies are selling JavaBeans you can plug into your own custom
applications. I have some I have written available free with source code. They
handle prompting, data validation and generating error messages for data keyed.
There are plain and dbaware components for dates, FormattedTextFields, phone
numbers, provinces, postal codes, etc. you can download.
Books
 |
recommend book⇒Mastering JavaBeans |
| | paperback |
|---|
| ISBN10: | 0-7821-2097-0 |
|---|
| ISBN13: | 978-0-7821-2097-4 |
|---|
| publisher: | Sybex |
| published: | 1997-05 |
| by: | Laurence Vanhelsuwé |
| 800-pages. Now out of print. |
|
Learning More
Sun’s Javadoc on the
PersistenceDelegate class : available: