SlideShare a Scribd company logo
1 of 39
JavaBeans
Definition: A Java Bean is a reusable software
component that can be manipulated visually in a
builder tool.
a software component model
Software components are self-contained software
units developed according to the motto.
Developed them once, run and reused them
everywhere.
A Java Bean is an ordinary java class that confirms the
following rules
1. It provides a default, no-argument constructor.
2. It should be serializable and implement the
Serializable interface.
3. It may have a number of properties which can be
read or written.
4. It may have a number of "getter" and "setter"
methods for accessing properties.
Advantages of Java Beans
1. Beans is platform independent, that means it can
be run anywhere.
2. Beans can work in different local platforms.
3. Methods, properties and events of Beans can be
controlled.
4. It is easy to configure Java beans
5. A bean can both receive and create events
6. Configuration settings of a bean can be stored
persistently and can be retrieved any time
How to write a java bean using coding standards
public class StudentsBean implements java.io.Serializable
{
private String firstName = null;
private String lastName = null;
public StudentsBean() { }
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public void setLastName(String lastName)
{
this.lastName = lastName; }
}
Bean Development Kit(BDK)
BDK is a development tool through which java beans can be
created, configured, executed or interconnected.
Installation
C:beans
Bean box
Run.bat
Starting the BeanBox
When you start the BeanBox, you'll see three
windows:
– ToolBox window
– BeanBox window
– Properties window
• The ToolBox window displays the JavaBeans
that are currently installed in the BeanBox
• The BeanBox window itself appears initially as
an empty window.
• the Properties window, displays the current
properties for the selected Bean
• Method tracer, used to keep an eye on the
activities of bean,mainly used for debugging
purpose.
Create and Configure an Instance of
the Molecule Bean
• Follow these steps
1. Position the cursor on the ToolBox entry labeled
Molecule and click the left mouse button.
2. Move the cursor to the BeanBox display area and
click the left mouse button.
3. You can reposition the Molecule Bean by
positioning the cursor over one of the hatched
borders and dragging the Bean.
4. You can change the molecule that is displayed by
changing the selection in the Properties window
Instrospection
• builder tools typically provide a property sheet
where one can conveniently set the properties of a
JavaBean component.
• In order to provide this service a builder tool needs
to examine the component for its features
(=properties, events and methods).This process is
referred to as “introspection”.
• Introspection is the automatic process of analyzing
a bean's design patterns to reveal the bean's
properties, events, and methods. This process
controls the publishing and discovery of bean
operations and properties.
• To obtain information about a specific JavaBean one
can use the static getBeanInfo() method of the
Introspector class.
• This method returns an instance of the BeanInfo
class, which describes all features a JavaBean
exposes.
• use of this method is shown in the following code
fragment:
FontSelector fs = new FontSelector ();
BeanInfo bi = Introspector . getBeanInfo (fs.
getClass ());
The following example represents code to perform introspection:
• import java.beans.BeanInfo;
• import java.beans.Introspector;
• import java.beans.IntrospectionException;
• import java.beans.PropertyDescriptor;
• public class BeanDemo
• {
• private final String name = "BeanDemo";
• private int size;
• public String getName()
• {
• return this.name;
• }
• public int getSize()
• {
• return this.size;
• }
• public void setSize( int size )
• {
• this.size = size;
• }
• public static void main( String[] args )
• throws IntrospectionException
• {
• BeanInfo info = Introspector.getBeanInfo( BeanDemo.class );
• for ( PropertyDescriptor pd : info.getPropertyDescriptors() )
• System.out.println( pd.getName() );
• }
• }
• The above example creates a non-visual bean
displays the following properties derived from
the BeanInfo object.
out put:
class
name
size
BeanInfo Interface
• 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.
Method Detail
• getBeanDescriptor
public BeanDescriptor getBeanDescriptor()
Gets the beans BeanDescriptor.
Returns:A BeanDescriptor providing overall
information about the bean
• getEventSetDescriptors
public EventSetDescriptor[] getEventSetDescriptors()
Gets the beans EventSetDescriptors.
Returns:An array of EventSetDescriptors
describing the kinds of events fired by this
bean
• getDefaultEventIndex
• public int getDefaultEventIndex()
• A bean may have a "default" event that is the
event that will mostly commonly be used by
humans when using the bean.
Returns:Index of default event in the
EventSetDescriptor array returned by
getEventSetDescriptors.Returns -1 if there is
no default event.
• getPropertyDescriptors
• public PropertyDescriptor[] getPropertyDescriptors()
Gets the beans PropertyDescriptors.
Returns:An array of PropertyDescriptors
describing the editable properties supported
by this bean.
• getDefaultPropertyIndex
• public int getDefaultPropertyIndex()
• A bean may have a "default" property that is the
property that will mostly commonly be initially
chosen for update by human's who are customizing
the bean.
• Returns:Index of default property in the
PropertyDescriptor array returned by
getPropertyDescriptors.Returns -1 if there is no
default property.
• getMethodDescriptors
• public MethodDescriptor[] getMethodDescriptors()
• Gets the beans MethodDescriptors.
• Returns:An array of MethodDescriptors
describing the externally visible methods
supported by this bean
• getAdditionalBeanInfo
public BeanInfo[] getAdditionalBeanInfo()
that provide additional information on the
current bean
• getIcon
public Image getIcon(int iconKind)
This method returns an image object that can
be used to represent the bean in toolboxes
Properties
• There exist four different kinds of properties a
JavaBean can expose:
1. Simple
2. Indexed
3. Bound
4. Constrained
• All types of property have in common that
they are characterized by a pair of set/get
methods.
Simple Properties
• As the name suggests, simple properties are
the simplest of the four.
• we would like to have a default font size,
which will be used as initial font size at
runtime.
• Design patterns, where N is the name of the
property and T is its type.
public T getN( );
public void setN(T arg);
The following listing shows a class that has three read/write simple
properties:
• public class Box {
• private double depth, height, width;
• public double getDepth( ) {
• return depth;
• }
• public void setDepth(double d) {
• depth = d;
• }
• public double getHeight( ) {
• return height;
• }
• public void setHeight(double h) {
• height = h;
• }
• public double getWidth( ) {
• return width;
• }
• public void setWidth(double w) {
• width = w;
• }
• }
Indexed Properties
• If a simple property can hold an array of value
they are no longer called simple but instead
indexed properties
• An indexed property may expose set/get
methods to read/write one element in the
array and/or so-called ’array getter/setter’
which read/write the entire array.
• design patterns, where N is the name of the
property and T is its type:
– public T getN(int index);
– public void setN(int index, T value);
– public T[ ] getN( );
– public void setN(T values[ ]);
• The following listing shows a class that has one read/write indexed
property:
• public class PieChart {
• private double data[ ];
• public double getData(int index) {
• return data[index];
• }
• public void setData(int index, double value) {
• data[index] = value;
• }
• public double[ ] getData( ) {
• return data;
• }
• public void setData(double[ ] values) {
• data = new double[values.length];
• System.arraycopy(values, 0, data, 0, values.length);
• }
• }
Bound Properties
• A Bean that has a bound property generates an
event when the property is changed.
• Bound Properties are the properties of a JavaBean
that inform its listeners about changes in its values.
• Bound Properties are implemented using the
PropertyChangeSupport class and its methods.
• Bound Properties are always registered with an
external event listener.
• The event is of type PropertyChangeEvent and is sent to
objects that previously registered an interest in receiving such
notifications.
• In order to provide this notification service a JavaBean needs
to have the following two methods:
public void
addPropertyChangeListener(PropertyChangeListener p)
{
changes.addPropertyChangeListener(p);
}
public void
removePropertyChangeListener(PropertyChangeListener p)
{
changes.removePropertyChangeListener(p);
}
Constrained Properties
• A Bean that has a constrained property generates
an event when an attempt is made to change its
value.
• Constrained Properties are implemented using the
PropertyChangeEvent class.
• The event is sent to objects that previously
registered an interest in receiving such notifications.
Those other objects have the ability to veto the
proposed change. This capability allows a Bean to
operate differently according to its run-time
environment.
• 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
Persistence
• Persistence is the ability to save a Bean to
nonvolatile storage and retrieve it at a later
time.
• Inorder to do this we take the help of BDK.
Saving the beans in the BDK :choose “file”
and then the “save” options.
Restoring the beans in the BDK:choose “file”
and then “load ” options.
The Java Beans API
• The Java Beans functionality is provided by a
set of classes and interfaces in the
java.beans package.
Interface Description
AppletInitializer Methods in this interface are used to
initialize Beans that are also applets.
BeanInfo This interface allows a designer to specify
information about the properties, events,
and methods of a Bean.
Customizer This interface allows a designer to provide
a graphical user interface through which a
Bean may be configured.
ExceptionListener A method in this interface is invoked
when an exception has occurred
PropertyChangeListener A method in this interface is invoked
when a bound property is changed.
PropertyEditor Objects that implement this interface
allow designers to change and display
property values
Interface Description
VetoableChangeListener A method in this interface is invoked
when a constrained property is changed.
Visibility Methods in this interface allow a Bean to
execute in environments where a
graphical user interface is not available.
Class Description
Encoder Encodes the state of a set of Beans. Can
be used to write this information to a
stream
EventHandler Supports dynamic event listener creation
EventSetDescriptor Instances of this class describe an event
that can be generated by a Bean
FeatureDescriptor This is the superclass of the
PropertyDescriptor,
EventSetDescriptor, and
MethodDescriptor
classes.
IndexedPropertyDescriptor Instances of this class describe an indexed
property of a Bean.
SimpleBeanInfo This class provides functionality that can
be used when writing BeanInfo classes
Class description
IntrospectionException An exception of this type is generated if a
problem occurs when analyzing a Bean.
Introspector This class analyzes a Bean and constructs
a BeanInfo object that describes the
component
MethodDescriptor Instances of this class describe a method
of a Bean.
ParameterDescriptor Instances of this class describe a method
parameter.
PropertyChangeEvent This event is generated when bound or
constrained
properties are changed
PropertyDescriptor Instances of this class describe a property
of a Bean.
PropertyEditorManager This class locates a PropertyEditor object
for agiven type.

More Related Content

What's hot (20)

Java beans
Java beansJava beans
Java beans
 
Awt controls ppt
Awt controls pptAwt controls ppt
Awt controls ppt
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
EJB .
EJB .EJB .
EJB .
 
object oriented methodologies
object oriented methodologiesobject oriented methodologies
object oriented methodologies
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Active x control
Active x controlActive x control
Active x control
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Java applets
Java appletsJava applets
Java applets
 
Generics
GenericsGenerics
Generics
 

Similar to Java beans

Similar to Java beans (20)

Javabean1
Javabean1Javabean1
Javabean1
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
 
Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)
 
Unit iv
Unit ivUnit iv
Unit iv
 
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
 
Java beans
Java beansJava beans
Java beans
 
CommercialSystemsBahman.ppt
CommercialSystemsBahman.pptCommercialSystemsBahman.ppt
CommercialSystemsBahman.ppt
 
Java beans
Java beansJava beans
Java beans
 
introduction of Java beans
introduction of Java beansintroduction of Java beans
introduction of Java beans
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
 
Java beans
Java beansJava beans
Java beans
 
React-Native Lecture 11: In App Storage
React-Native Lecture 11: In App StorageReact-Native Lecture 11: In App Storage
React-Native Lecture 11: In App Storage
 
Introduction of Life Cycle.pptx
Introduction of Life Cycle.pptxIntroduction of Life Cycle.pptx
Introduction of Life Cycle.pptx
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5
 
Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)
 
Spring essentials 2 Spring Series 02)
Spring essentials 2 Spring Series 02)Spring essentials 2 Spring Series 02)
Spring essentials 2 Spring Series 02)
 
Session 6 Tp6
Session 6 Tp6Session 6 Tp6
Session 6 Tp6
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
 

More from Rajkiran Mummadi (16)

Servlets
ServletsServlets
Servlets
 
Php
PhpPhp
Php
 
Java script
Java scriptJava script
Java script
 
Ajax.pdf
Ajax.pdfAjax.pdf
Ajax.pdf
 
Google glasses
Google glassesGoogle glasses
Google glasses
 
Environmental hazards
Environmental hazardsEnvironmental hazards
Environmental hazards
 
Wcharging
WchargingWcharging
Wcharging
 
Wireless charging
Wireless chargingWireless charging
Wireless charging
 
Standard bop
Standard bopStandard bop
Standard bop
 
Russian technology in indian banking system 1
Russian technology in indian banking system 1Russian technology in indian banking system 1
Russian technology in indian banking system 1
 
Ai presentation
Ai presentationAi presentation
Ai presentation
 
Loon
LoonLoon
Loon
 
Triggers
TriggersTriggers
Triggers
 
autonomous cars
autonomous carsautonomous cars
autonomous cars
 
ET3
ET3ET3
ET3
 
demonetisation
demonetisationdemonetisation
demonetisation
 

Recently uploaded

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Recently uploaded (20)

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

Java beans

  • 1. JavaBeans Definition: A Java Bean is a reusable software component that can be manipulated visually in a builder tool. a software component model Software components are self-contained software units developed according to the motto. Developed them once, run and reused them everywhere.
  • 2. A Java Bean is an ordinary java class that confirms the following rules 1. It provides a default, no-argument constructor. 2. It should be serializable and implement the Serializable interface. 3. It may have a number of properties which can be read or written. 4. It may have a number of "getter" and "setter" methods for accessing properties.
  • 3. Advantages of Java Beans 1. Beans is platform independent, that means it can be run anywhere. 2. Beans can work in different local platforms. 3. Methods, properties and events of Beans can be controlled. 4. It is easy to configure Java beans 5. A bean can both receive and create events 6. Configuration settings of a bean can be stored persistently and can be retrieved any time
  • 4. How to write a java bean using coding standards public class StudentsBean implements java.io.Serializable { private String firstName = null; private String lastName = null; public StudentsBean() { } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public void setFirstName(String firstName) { this.firstName = firstName; } public void setLastName(String lastName) { this.lastName = lastName; } }
  • 5. Bean Development Kit(BDK) BDK is a development tool through which java beans can be created, configured, executed or interconnected. Installation C:beans Bean box Run.bat
  • 6. Starting the BeanBox When you start the BeanBox, you'll see three windows: – ToolBox window – BeanBox window – Properties window
  • 7.
  • 8. • The ToolBox window displays the JavaBeans that are currently installed in the BeanBox • The BeanBox window itself appears initially as an empty window. • the Properties window, displays the current properties for the selected Bean • Method tracer, used to keep an eye on the activities of bean,mainly used for debugging purpose.
  • 9. Create and Configure an Instance of the Molecule Bean • Follow these steps 1. Position the cursor on the ToolBox entry labeled Molecule and click the left mouse button. 2. Move the cursor to the BeanBox display area and click the left mouse button. 3. You can reposition the Molecule Bean by positioning the cursor over one of the hatched borders and dragging the Bean. 4. You can change the molecule that is displayed by changing the selection in the Properties window
  • 10.
  • 11. Instrospection • builder tools typically provide a property sheet where one can conveniently set the properties of a JavaBean component. • In order to provide this service a builder tool needs to examine the component for its features (=properties, events and methods).This process is referred to as “introspection”. • Introspection is the automatic process of analyzing a bean's design patterns to reveal the bean's properties, events, and methods. This process controls the publishing and discovery of bean operations and properties.
  • 12. • To obtain information about a specific JavaBean one can use the static getBeanInfo() method of the Introspector class. • This method returns an instance of the BeanInfo class, which describes all features a JavaBean exposes. • use of this method is shown in the following code fragment: FontSelector fs = new FontSelector (); BeanInfo bi = Introspector . getBeanInfo (fs. getClass ());
  • 13. The following example represents code to perform introspection: • import java.beans.BeanInfo; • import java.beans.Introspector; • import java.beans.IntrospectionException; • import java.beans.PropertyDescriptor; • public class BeanDemo • { • private final String name = "BeanDemo"; • private int size; • public String getName() • { • return this.name; • } • public int getSize() • { • return this.size; • } • public void setSize( int size ) • { • this.size = size; • } • public static void main( String[] args ) • throws IntrospectionException • { • BeanInfo info = Introspector.getBeanInfo( BeanDemo.class ); • for ( PropertyDescriptor pd : info.getPropertyDescriptors() ) • System.out.println( pd.getName() ); • } • }
  • 14. • The above example creates a non-visual bean displays the following properties derived from the BeanInfo object. out put: class name size
  • 15. BeanInfo Interface • 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.
  • 16. Method Detail • getBeanDescriptor public BeanDescriptor getBeanDescriptor() Gets the beans BeanDescriptor. Returns:A BeanDescriptor providing overall information about the bean
  • 17. • getEventSetDescriptors public EventSetDescriptor[] getEventSetDescriptors() Gets the beans EventSetDescriptors. Returns:An array of EventSetDescriptors describing the kinds of events fired by this bean
  • 18. • getDefaultEventIndex • public int getDefaultEventIndex() • A bean may have a "default" event that is the event that will mostly commonly be used by humans when using the bean. Returns:Index of default event in the EventSetDescriptor array returned by getEventSetDescriptors.Returns -1 if there is no default event.
  • 19. • getPropertyDescriptors • public PropertyDescriptor[] getPropertyDescriptors() Gets the beans PropertyDescriptors. Returns:An array of PropertyDescriptors describing the editable properties supported by this bean.
  • 20. • getDefaultPropertyIndex • public int getDefaultPropertyIndex() • A bean may have a "default" property that is the property that will mostly commonly be initially chosen for update by human's who are customizing the bean. • Returns:Index of default property in the PropertyDescriptor array returned by getPropertyDescriptors.Returns -1 if there is no default property.
  • 21. • getMethodDescriptors • public MethodDescriptor[] getMethodDescriptors() • Gets the beans MethodDescriptors. • Returns:An array of MethodDescriptors describing the externally visible methods supported by this bean
  • 22. • getAdditionalBeanInfo public BeanInfo[] getAdditionalBeanInfo() that provide additional information on the current bean • getIcon public Image getIcon(int iconKind) This method returns an image object that can be used to represent the bean in toolboxes
  • 23. Properties • There exist four different kinds of properties a JavaBean can expose: 1. Simple 2. Indexed 3. Bound 4. Constrained • All types of property have in common that they are characterized by a pair of set/get methods.
  • 24. Simple Properties • As the name suggests, simple properties are the simplest of the four. • we would like to have a default font size, which will be used as initial font size at runtime.
  • 25. • Design patterns, where N is the name of the property and T is its type. public T getN( ); public void setN(T arg);
  • 26. The following listing shows a class that has three read/write simple properties: • public class Box { • private double depth, height, width; • public double getDepth( ) { • return depth; • } • public void setDepth(double d) { • depth = d; • } • public double getHeight( ) { • return height; • } • public void setHeight(double h) { • height = h; • } • public double getWidth( ) { • return width; • } • public void setWidth(double w) { • width = w; • } • }
  • 27. Indexed Properties • If a simple property can hold an array of value they are no longer called simple but instead indexed properties • An indexed property may expose set/get methods to read/write one element in the array and/or so-called ’array getter/setter’ which read/write the entire array.
  • 28. • design patterns, where N is the name of the property and T is its type: – public T getN(int index); – public void setN(int index, T value); – public T[ ] getN( ); – public void setN(T values[ ]);
  • 29. • The following listing shows a class that has one read/write indexed property: • public class PieChart { • private double data[ ]; • public double getData(int index) { • return data[index]; • } • public void setData(int index, double value) { • data[index] = value; • } • public double[ ] getData( ) { • return data; • } • public void setData(double[ ] values) { • data = new double[values.length]; • System.arraycopy(values, 0, data, 0, values.length); • } • }
  • 30. Bound Properties • A Bean that has a bound property generates an event when the property is changed. • Bound Properties are the properties of a JavaBean that inform its listeners about changes in its values. • Bound Properties are implemented using the PropertyChangeSupport class and its methods. • Bound Properties are always registered with an external event listener.
  • 31. • The event is of type PropertyChangeEvent and is sent to objects that previously registered an interest in receiving such notifications. • In order to provide this notification service a JavaBean needs to have the following two methods: public void addPropertyChangeListener(PropertyChangeListener p) { changes.addPropertyChangeListener(p); } public void removePropertyChangeListener(PropertyChangeListener p) { changes.removePropertyChangeListener(p); }
  • 32. Constrained Properties • A Bean that has a constrained property generates an event when an attempt is made to change its value. • Constrained Properties are implemented using the PropertyChangeEvent class. • The event is sent to objects that previously registered an interest in receiving such notifications. Those other objects have the ability to veto the proposed change. This capability allows a Bean to operate differently according to its run-time environment.
  • 33. • 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
  • 34. Persistence • Persistence is the ability to save a Bean to nonvolatile storage and retrieve it at a later time. • Inorder to do this we take the help of BDK. Saving the beans in the BDK :choose “file” and then the “save” options. Restoring the beans in the BDK:choose “file” and then “load ” options.
  • 35. The Java Beans API • The Java Beans functionality is provided by a set of classes and interfaces in the java.beans package.
  • 36. Interface Description AppletInitializer Methods in this interface are used to initialize Beans that are also applets. BeanInfo This interface allows a designer to specify information about the properties, events, and methods of a Bean. Customizer This interface allows a designer to provide a graphical user interface through which a Bean may be configured. ExceptionListener A method in this interface is invoked when an exception has occurred PropertyChangeListener A method in this interface is invoked when a bound property is changed. PropertyEditor Objects that implement this interface allow designers to change and display property values
  • 37. Interface Description VetoableChangeListener A method in this interface is invoked when a constrained property is changed. Visibility Methods in this interface allow a Bean to execute in environments where a graphical user interface is not available.
  • 38. Class Description Encoder Encodes the state of a set of Beans. Can be used to write this information to a stream EventHandler Supports dynamic event listener creation EventSetDescriptor Instances of this class describe an event that can be generated by a Bean FeatureDescriptor This is the superclass of the PropertyDescriptor, EventSetDescriptor, and MethodDescriptor classes. IndexedPropertyDescriptor Instances of this class describe an indexed property of a Bean. SimpleBeanInfo This class provides functionality that can be used when writing BeanInfo classes
  • 39. Class description IntrospectionException An exception of this type is generated if a problem occurs when analyzing a Bean. Introspector This class analyzes a Bean and constructs a BeanInfo object that describes the component MethodDescriptor Instances of this class describe a method of a Bean. ParameterDescriptor Instances of this class describe a method parameter. PropertyChangeEvent This event is generated when bound or constrained properties are changed PropertyDescriptor Instances of this class describe a property of a Bean. PropertyEditorManager This class locates a PropertyEditor object for agiven type.