AdvancedJavaProgramming-SLIDES02-UNIT2-FP2005-Ver 1.0
AdvancedJavaProgramming-SLIDES02-UNIT2-FP2005-Ver 1.0
(J2EE LC)
Unit 4 - Java Beans
Course Objective
Introducing Java Beans
Naming conventions
Summary
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 2
Technologies Ltd Version 1.00
References
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 3
Technologies Ltd Version 1.00
What is a Java Bean?
Component
– An artifact that is one of the individual parts of which makes a composite entity
Various Frameworks and Tools can use Java Bean components to build
something bigger
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 4
– Example 1: An address component holds address of a person
Technologies Ltd Versionin a program
1.00
What is Java Beans? (Continued…)
Java Beans API provides a framework for defining software components that
are
– Reusable: Component which is capable of being used again and again
– Modular: A solution made of several discrete pieces, so that any piece can be
replaced without rebuilding the whole solution
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 5
Technologies Ltd Version 1.00
Frameworks and Builder tools which use Java Beans components use Java
class Employee {
Simple Java Bean private int employeeNumber;
private String employeeName;
Employee Class ...
public void setEmployeeNumber
– Has all data members
(int employeeNumber) {
private
this.employeeNumber=
– Does not have a employeeNumber;
constructor }
public int getEmployeeNumber() {
– A pair of public Get/Set
return employeeNumber;
methods for all or most
}
member variables public void setEmployeeName
– Names of Get/Set methods (String employeeName) {
should match the variable this.employeeName=
employeeName;
names
}
Results in an Employee public String getEmployeeName() {
Bean return employeeName;
}
Has properties
...
ER/CORP/CRS/LA22/003
– employeeNumber } © 2005, Infosys
Copyright 6
Technologies Ltd Version 1.00
– employeeName
Why Java Beans?
Many real life situations require components to work with various frameworks and
libraries
Data is in text files, XML files or other textual forms have to be mapped programmatically
in many applications
– Names in text form can be mapped to variable names of a class
– Example: <employeeNumber>29853</employeeNumber>
<employeeName>Tom</employeeName>
...
</Employee>
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 8
Technologies Ltd Version 1.00
Where do we use Java Beans?
Data handling and data intensive applications for mapping textual data to variables
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 9
Technologies Ltd Version 1.00
Java Beans in User Interface
BDK (Bean Development Kit) was a specification from Sun for creating and using
reusable UI based Java Beans
– Application Builder or similar GUI frameworks can understand and use these components to
build GUI Screens
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 10
Technologies Ltd Version 1.00
Java Beans in User Interface (Continued…)
Application Builder tool and other GUI Frameworks for using Java Beans
– Use Reflection API and display all the properties and events offered by a Java Bean in a toolbar
in the development environment
– Developer can manipulate properties and write event handler code in development environment
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 11
Technologies Ltd Version 1.00
Application Builder Tool Java Bean components
(Classified in tabs)
Button Bean
Slider Bean
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 13
Technologies Ltd Version 1.00
Naming Conventions
Bean
– Class name: Any user defined name
Properties
– What makes up a property?
– Example:
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 14
Technologies Ltd Version 1.00
Summary
Java Beans is the de-facto component framework used in Java applications
– Used in data manipulation, server side code
– Used rarely in GUI applications
Naming conventions
– For Bean
– For Properties
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 15
Technologies Ltd Version 1.00
Thank you
ER/CORP/CRS/LA22/003
Copyright © 2005, Infosys 16
Technologies Ltd Version 1.00