Introduction To Java Beans
Introduction To Java Beans
Introduction To Java Beans
Prepared by SCCE_III-CSE
Page 1
VENDOR
DESCRIPTION
Java Workshop2.0
IBM
Jbuilder
Borland Inc.
SunMicroSystems., Inc.,
Page 2
BeanInfo
Methods
JavaBean
Component
Events
Properties
Customizer
Prepared by SCCE_III-CSE
JAR
Page 3
BeanBox window:
Is a workspace for creating the layout of JavaBean application.
The following figure shows the BeanBox window:
Prepared by SCCE_III-CSE
Page 4
Page 5
The files of a JavaBean application are compressed and grouped as JAR files to reduce
the size and the download time of the files.
The syntax to create a JAR file from the command prompt is:
jar <options> <file_names>
The file_names is a list of files for a JavaBean application that are stored in the JAR file.
The various options that you can specify while creating a JAR file are:
c: Indicates the new JAR file is created.
f: Indicates that the first file in the file_names list is the name of the JAR
file.
m: Indicates that the second file in the file_names list is the name of the
manifest file.
t: Indicates that all the files and resources in the JAR file are to be
displayed in a tabular format.
v: Indicates that the JAR file should generate a verbose output.
x: Indicates that the files and resources of a JAR file are to be extracted.
o: Indicates that the JAR file should not be compressed.
m: Indicates that the manifest file is not created.
6. Start BDK
Go to->
C:\bdk1_1\beans\beanbox
Click on run.bat file. When we click on run.bat file the BDK software automatically started.
Prepared by SCCE_III-CSE
Page 6
Prepared by SCCE_III-CSE
Page 7
Boolean Properties:
A Boolean property is a property which is used to represent the values True or False.
Have either of the two values, TRUE or FALSE.
It can identified by the following methods:
Syntax:
Let N be the name of the property and T be the type of the value then
public boolean isN();
public void setN(boolean parameter);
public Boolean getN();
public boolean is<PropertyName>()
public boolean get<PropertyName>()
First or second pattern can be used to retrieve the value of a Boolean.
public void set<PropertyName>(boolean value)
For getting the values isN() and getN() methods are used and for setting the Boolean values setN() method is
used.
Prepared by SCCE_III-CSE
Page 8
Indexed Properties:
Indexed Properties are consists of multiple values.
If a simple property can hold an array of value they are no longer called simple but
instead indexed properties. The methods signature has to be adapted accordingly. An
indexed property may expose set/get methods to read/write one element in the array
(so-called index getter/setter) and/or so-called array getter/setter which read/write
the entire array.
Indexed Properties enable you to set or retrieve the values from an array of property values.
Indexed Properties are retrieved using the following get methods:
Syntax:public int[] get<PropertyName>()
Ex:
private double data[];
public double getData(int index)
{
return data[index];
}
Syntax:public property_datatype get<PropertyName>(int index)
Ex:
public void setData(int index,double value)
{
Data[index]=value;
}
Indexed Properties are specified using the following set methods:
Syntax:
public void set<PropertyName>(int index, property_datatype value)
EX:
public double[] getData()
{
return data;
}
Syntax :
public void set<PropertyName>(property_datatype[] property_array)
Ex:
public void setData(double[] values)
{
}
The properties window of BDK does not handle indexed properties. Hence the output can not be displayed here.
Prepared by SCCE_III-CSE
Page 9
Constrained Properties:
It generates an event when an attempt is made to change it value
Constrained Properties are implemented using the PropertyChangeEvent class.
The event is sent to objects that previously registered an interest in receiving an such notification
Those other objects have the ability to veto the proposed change
This allows a bean to operate differently according to the runtime environment
A bean property for which a change to the property results in validation by another bean. The other bean may
reject the change if it is not appropriate.
Constrained Properties are the properties that are protected from being changed by other JavaBeans.
Constrained Properties are registered with an external event listener that has the ability to either accept or reject
the change in the value of a constrained property.
Constrained Properties can be retrieved using the get method. The prototype of the get method is:
Syntax:public string get<ConstrainedPropertyName>()
Can be specified using the set method. The prototype of the set method is:
Syntax :public string set<ConstrainedPropertyName>(String str)throws PropertyVetoException
Page 10
Prepared by SCCE_III-CSE
Page 11
Persistence
Persistence means an ability to save properties and events of our beans to non-volatile storage and retrieve later.
It has the ability to save a bean to storage and retrieve it at a later time Configuration settings are saved It is
implemented by Java serialization.
If a bean inherits directly or indirectly from Component class it is automatically Serializable.
Transient keyword can be used to designate data members of a Bean that should not be serialized.
Enables developers to customize Beans in an application builder, and then retrieve those Beans, with
customized features intact, for future use,perhaps in another environment.
Java Beans supports two forms of persistence:
Automatic persistence
External persistence
Automatic Persistence:
Automatic persistence are javas built-in serialization mechanism to save and restore the state of a bean.
External Persistence:
External persistence, on the other hand, gives you the option of supplying your own custom classes to control
precisely how a bean state is stored and retrieved.
Juggle Bean.
Building an applet
Your own bean
Customizers:
The Properties window of the BDK allows a developer to modify the several properties of the Bean.
Property sheet may not be the best user interface for a complex component
It can provide step-by-step wizard guide to use component
It can provide a GUI frame with image which visually tells what is changed such as radio button, check box,
...
It can customize the appearance and behavior of the properties
Online documentation can also be provided. A Bean developer has great flexibility to develop a customizer
that can differentiate his or her product in the marketplace.
To make it easy to configure a java beans component
Enables a developer to use an application builder tool to customize the appearance and behavior of a bean
Prepared by SCCE_III-CSE
Page 12
BeanInfo
A bean implementor who wishes to provide explicit information about their bean may provide a
BeanInfo class that implements this BeanInfo interface and provides explicit information about the
methods, properties, events, etc, of their bean.
Customizer
A customizer class provides a complete custom GUI for customizing a target Java Bean.
DesignMode
ExceptionListener
PropertyChangeListener
PropertyEditor
A PropertyEditor class provides support for GUIs that want to allow users to edit a property value
of a given type.
VetoableChangeListener
Visibility
Under some circumstances a bean may be run on servers where a GUI is not available.
Class Summary
BeanDescriptor
Beans
DefaultPersistenceDelegate
Encoder
An Encoder is a class which can be used to create files or streams that encode the
state of a collection of JavaBeans in terms of their public APIs.
EventHandler
EventSetDescriptor
Expression
Prepared by SCCE_III-CSE
Page 13
FeatureDescriptor
IndexedPropertyChangeEvent
IndexedPropertyDescriptor
Introspector
The Introspector class provides a standard way for tools to learn about the properties,
events, and methods supported by a target Java Bean.
MethodDescriptor
ParameterDescriptor
PersistenceDelegate
The PersistenceDelegate class takes the responsibility for expressing the state of an
instance of a given class in terms of the methods in the class's public API.
PropertyChangeEvent
PropertyChangeListenerProxy
PropertyChangeSupport
This is a utility class that can be used by beans that support bound properties.
PropertyDescriptor
A PropertyDescriptor describes one property that a Java Bean exports via a pair of
accessor methods.
PropertyEditorManager
The PropertyEditorManager can be used to locate a property editor for any given
type name.
PropertyEditorSupport
SimpleBeanInfo
This is a support class to make it easier for people to provide BeanInfo classes.
Statement
VetoableChangeListenerProxy
VetoableChangeSupport
This is a utility class that can be used by beans that support constrained properties.
XMLDecoder
The XMLDecoder class is used to read XML documents created using the
XMLEncoder and is used just like the ObjectInputStream.
XMLEncoder
Prepared by SCCE_III-CSE
Page 14
Prepared by SCCE_III-CSE
Page 15
beanBox design and test behavior (selected Bean, etc.), and makes the BeanBox
behave like an application.
Hide Invisible Beans
Hides invisible Beans.
Prepared by SCCE_III-CSE
Page 16