Post on 24-Dec-2015
Introducing JavaBeans
Identify the features of a JavaBean
Create and add a bean to an application
Manipulate bean properties using accessor and mutator methods
Introducing JavaBeans
Getting Started
Object
Is a runtime instance of a class
Software components:
Are reusable objects
Pluggable into any software application from any vendor
Examples - Spell-check utility, find and replace utility
JavaBeans
Are reusable and self-contained software components created using Java
Introducing JavaBeans
Getting Started (Contd.)
JavaBeans – Development Phases:
Construction phase
Involves creation of a JavaBean and its user interface
Build phase
Involves placing the JavaBean into the target container
Execution Phase
Involves execution of the the container application in which the JavaBean is placed
Introducing JavaBeans
Getting Started (Contd.)
Construction Phase involves creation of the following:
.class files
.mft file
.jar file
Elements of a JavaBean
Properties
Are the private member data contained in a JavaBean
Introducing JavaBeans
Getting Started (Contd.)
Methods
Are the public member functions used to:
Manipulate bean properties
Expose bean functionality
Events
Are used to communicate changes in bean property values or changes in its state to other beans
Introducing JavaBeans
Getting Started (Contd.)
The JavaBean Component Specification
Customization
Is the ability of a JavaBean to allow its properties to be changed
Persistence
Is the ability of a bean to save its state
Communication
Is the ability of a bean to inform changes in its attributes to other beans and to the container application
Introducing JavaBeans
Getting Started (Contd.)
Introspection
Is the ability of a bean to be queried by external applications
Types of JavaBeans
Bean type Description
Control beans Are used to create graphical user interface components
Container beans Are used to hold other Java beans
Invisible Runtime beans
Are used to create components that perform a specific task in the background
Introducing JavaBeans
Building an Application Using Existing Beans
To identify the software to be used to build and test the components and familiarize yourself with the software by creating an application similar to the one shown below:
Introducing JavaBeans
Task List
Identify the software to be used to create the application
Identify the beans to be added to the BeanBox window
Add the beans to the BeanBox window
Associate events with the beans
Save and execute the application
Introducing JavaBeans
Task 1: Identify the software to be used to create the application
Beans Development Kit
Is used as a tool to:
Build bean based applications
Test bean functionality
Contains several example beans
To start BDK
Execute the run.bat file from the command prompt.
Introducing JavaBeans
Task 1: Identify the software to be used to createthe application (Contd.)
The following windows appear on starting BDK:
Window name Description
ToolBox Contains a list of sample beans supplied with BDK
BeanBox Acts as a form or a container for the beans that make up an application
Properties Displays the properties of the bean currently selected in the BeanBox window
Method Tracer Keeps track of method invocations across beans
Introducing JavaBeans
Task 1: Identify the software to be used to createthe application (Contd.)
Result:
BDK will be used to test the beans
Introducing JavaBeans
Task 2: Identify the beans to be added to the BeanBox
Result:
The application uses two beans that are supplied with the BDK software
Juggler bean
Two instances of the OurButton bean
Introducing JavaBeans
Task 3: Add the beans to the BeanBox window
Task 4: Associate events with the beans
Task 5: Save and execute the application
Introducing JavaBeans
The Juggler bean is an example of a ____ type of bean.
Which window of BDK is used to change the background color of a bean?
Which window of BDK is used to build a bean application?
Introducing JavaBeans
Creating Beans and Building Applications
A customer can access his account only after entering the pin number. You need to construct and test the component for the ATM application. The specifications for the component are given below:
It should display the logo of the bank as an animation. You might plug in the login component into the ATM application of any bank. So, the logo should be modifiable according to the ATM application of a particular bank into which the component is plugged in
It should accept the pin number of a customer
Introducing JavaBeans
Creating Beans and Building Applications (Contd.)
It should contain a method that checks if the pin number entered by a customer is present in the Earnest Bank database. This feature is specific to the Earnest Bank ATM application
After you create the login component, build a sample application and test the functionality of the component. The user interface of the sample login application should look similar to the one shown:
Introducing JavaBeans
Creating Beans and Building Applications (Contd.)
The user interface of the sample login application should look similar to the one shown:
Introducing JavaBeans
Task List
Identify the controls to be used
Identify the properties to be exposed by the bean
Identify the methods to be supported by the bean
Create the User Interface of the bean
Add code to expose the bean properties
Code the methods to be supported by the bean
Save and compile the program
Create the .mft file
Create the .jar file
Introducing JavaBeans
Task List
Load the bean into BDK
Build an application using the bean
Execute the application and verify the functionality of the bean
Introducing JavaBeans
Task 1: Identify the controls to be used
Result:
The controls to be used are:
A label and text field control for accepting the pin number
A label control for displaying the bank logo
Introducing JavaBeans
Task 2: Identify the properties to be exposed by the bean
Result:
The logo property should be exposed
Introducing JavaBeans
Task 3: Identify the methods to be supported bythe bean
Result:
A method named validatePinNo()needs to be coded in the component
Task 4: Create the User Interface of the bean
Introducing JavaBeans
Task 5: Add code to expose the bean properties
Properties of a Bean:
Are the characteristics of a bean
Are used to change the appearance and behavior of a bean
Example:
Properties that have to be exposed by a spell check utility can be coded as:
private String language;
private String dictionaryPath;
Introducing JavaBeans
Task 5: Add code to expose the bean properties(Contd.)
Accessor and Mutator Methods
Are used to make the properties of a bean available to the outside world
Are used to ensure the integrity of bean data
get method
Allows the current value of a property to be read
set method
Allows the current value of the property to be changed
Introducing JavaBeans
Task 6: Code the methods to be supported by the bean
Task 7: Save and compile the program
Introducing JavaBeans
Task 8: Create the .mft file
The Manifest file:
Is used by the target application to recognize a JavaBean
Is saved with a .mft extension
Contains a list of all class files that make up a JavaBean
Introducing JavaBeans
Task 9: Create the .jar file
The JAR file:
Is similar to a zip file
Is used to package a JavaBean for distribution
Contains the manifest file and all other files such as the class files and picture files of the bean
Has a .jar extension
Introducing JavaBeans
Task 10: Load the bean into BDK
Task 11: Build an application using the bean
Task 12: Execute the application and verify thefunctionality of the bean
Introducing JavaBeans
Creating Beans and Building Applications(try out)
A component needs to be created that accepts the login id and password of a customer. The component should wait for 30 seconds before the user enters the login information. The code for the component is given below. You need to modify the code to do the following:
If the user does not login for the specified time, a login time out message should be displayed
The time out message to be displayed will be specified during the build phase
The component should be pluggable into the ATM application of any bank
Introducing JavaBeans
An object is a run-time instance of a class. A component is a reusable object that can be embedded into any software application from any vendor. The SpellCheck utility is an example of a component
Beans created using Java takes advantage of all the security and platform independent features of Java
A JavaBean exists in one of the following three phases: the construction phase, the build phase, and the execution phase
Introducing JavaBeans
As per the JavaBean Component Specification, a simple Java object must support the following five features for it to become a JavaBean:
Properties
Customization
Persistence
Communication
Introspection
Introducing JavaBeans
You can create three types of beans:
Control beans
Container beans
Invisible run-time beans
A wide variety of application development environments such as Forte For Java, IBM Visual Age, Kawa, Beans Development Kit (BDK) and Symantec Visual Cafe are available in the market that support the creation, building, and testing of Java beans
BDK can be used as build tool to build bean applications or as a testing tool to test the beans for their intended functionality
Introducing JavaBeans
Execute the run.bat file from the command prompt to start BDK
On starting BDK, the ToolBox palette, the BeanBox window, and the Properties window are displayed
BDK consists of several re-usable sample beans such as the Juggler bean and the OurButton bean
Properties are the characteristics of a bean and are similar to the data members of a class. By changing the properties, you can change the appearance and behavior of a bean
The get and set accessor methods are used to expose the bean properties to external applications
Introducing JavaBeans
The manifest file contains information about a bean such as the name of the bean and the files present in the .jar file of the bean
JavaBeans are packaged and distributed as .jar files