Java Reference
In-Depth Information
A: No problem. A JavaBean can have a separate class, called a Bean-
Info class, which specifies the properties, methods, and events of
a bean. Most beans have a BeanInfo class, whether or not they
started out as a JavaBean.
Q: Suppose that I have a collection of JavaBeans. How do I hook
them together?
A: Beans are hooked together using a GUI builder tool, typically one
of the popular IDEs such as Visual Café or JBuilder. These builder
tools generate the code that hooks the beans together in the man-
ner that you need. In this topic, I will show you how to use Sun's
Bean Builder tool, which is freely downloadable from its Web site.
Q: What if the bean is not a GUI component, such as a bean that
searches a database?
A: You still hook it together with other beans using a GUI builder tool.
A bean does not need to be a GUI component, and in fact, most
beans do not have any GUI aspect to them.
Q: Why not just write the code yourself, instead of relying on the tool?
A: I suppose you could, but why not let a tool do the work for you?
An interesting aspect of JavaBeans is that you do not need to be a
Java programmer to hook them together. As long as you under-
stand properties, events, and methods, you can create a Java
application by hooking together a collection of JavaBeans.
Q: Do these builder tools need the source code of my beans so they
can determine the method names in my bean class?
A: No. The bean builder tools use a process called introspection to
determine the properties, methods, and events of a bean, which
are determined by public methods in the bean class. As a part of
introspection, the builder tools use the Java Reflection API to
determine the signatures of the methods in a bean class. The
Reflection API is not exclusive to JavaBeans; you can perform
reflection on any bytecode file.
Now that I have introduced you briefly to JavaBeans, let's look at the details
of how they are written and used. I will start with a discussion on simple prop-
erties, which will help demonstrate the simpler aspects of beans. Then, I will
show you how to view and change the simple properties of a bean using Sun's
Bean Builder.
Search WWH ::




Custom Search