8/15/2007

JavaBeans

JavaBeans technology is the component architecture for the Java Platform. The other component architecture is EJB, but JavaBeans and EJBs are entirely different beasts.

A JavaBean is a reusable software component. It is a Java class that defines properties and that communicates with other Beans via events. Properties can be defined within the JavaBean class definition, or they can be inherited from other classes. A Bean, however, is not required to inherit from any particular class or interface. The idea behind JavaBeans is to help develop and use reusable components and that is backed by specifications by which 'beans' abide. It's
the specification that ensures 'beans' integrability. Apart from the sepcificaitons, beans are just regular java classes (unlike ejbs!).

The major benifits of JavaBeans is that beans' properties can be manipulated in a visual builder tool like NetBeans. It can be simple, such as buttons, text fields, list boxes, scrollbars, and dialogs. Or they may be more complex software components to handle business logic or a spell-checker.

You certainly can use other pre-built objects in Java, but for that we must have an intimate knowledge of the object's interface at the code level. Additionally, you must integrate the object into your code programmatically.

JavaBeans components expose their own interfaces visually, enabling you to edit their properties without programming. Furthermore, you can use a visual editor to simply "drop" a JavaBeans component directly into an application without writing any code. This is an entirely new level of flexibility and reuse not previously attainable in Java alone.

The real value of JavaBeans is while designing/developing a software which uses these components, you can visually integrate these components with the rest of the system.The component need not be visible in a running application; they only need to be visible in the builder tools when the application is constructed by a builder tool. A programmer can move, query, or visually hook together components while operating a builder tool. Often, such components do their work while the application is running, though they are invisible to the user.

JavaBeans that represent graphical components and that are meant to be visible must inherit from a java.awt. Component such as the java.awt.Canvas class, so that they can be added to visual containers.

The following list briefly describes key bean concepts:

Introspection: Builder tools discover a bean's features (that is, its properties, methods, and events) by a process known as introspection. Beans support introspection in two ways:
By adhering to specific rules, known as design patterns, when naming bean features. The Introspector class examines beans for these design patterns to discover bean features. The Introspector class relies on the core reflection API.
By explicitly providing property, method, and event information with a related bean information class. A bean information class implements the BeanInfo interface. A BeanInfo class explicitly lists those bean features that are to be exposed to application builder tools.

Properties: Properties are the appearance and behavior characteristics of a bean that can be changed at design time. Builder tools introspect on a bean to discover its properties and expose those properties for manipulation.

Customization: Beans expose properties so they can be customized at design time. Customization is supported in two ways: by using property editors, or by using more sophisticated bean customizers.

Events: Beans use events to communicate with other beans. A bean that is to receive events (a listener bean) registers with the bean that fires the event (a source bean). Builder tools can examine a bean and determine which events that bean can fire (send) and which it can handle (receive).

Persistence: Persistence enables beans to save and restore their state. After changing a bean's properties, you can save the state of the bean and restore that bean at a later time with the property changes intact. The JavaBeans architecture uses Java Object Serialization to support persistence.

References:
java.sun.com  docs.rinet.ru  forum.java.sun.com

Property, Attribute and Field
(This is just an opinion and there is no Standard way of distinguishing the three.)
JavaBeans conventions for getters and setters allows us to expose properties. Those properties don’t have to be backed up by fields, but in many cases they are.
e.g. Circle's radius, diameter, circumference. We may have only one variable (field) 'radius' and can still expose all other properties. Attribute is more synonymous to Property.

References:
clintshank.javadevelopersjournal.com

No comments:

Post a Comment