1/50
JAVA BEANS
• JavaBeans is the one of major Reusable
software component developed by Sun
Microsystems for the Java. It is mainly used in
the builder tool.
• JavaBeans is a platform-independent,
component model written in JAVA language,
which can be changed and customized.
• Java Bean contains a public constructor with
no arguments, properties and
accessor/mutator methods for those
properties. 2/50
JAVA BEANS – Contd;
• A JavaBeans is just a java class with the
following requirements.
– It has a public no-args constructor
– It has 'set' and 'get' methods for its properties.
– It may have any general functions.
– If required it must be Serializable.
3/50
JAVA BEANS Example – Contd;
4/50
Public class sampleBean
{
private String name;
private int age;
public sampleBean() {
}
public String getName()
{
-------------
}
public void setName(String name){
this.name=name;
}
public String getAge(){
-------------
}
public void setAge(String age){
this.age=age;
} }
JAVA BEANS - Advantages
• Java Bean is the Re-usable component, simply
we can call “Write once and use everywhere”
concept
• It is very simple and flexible to use.
• Portable and platform independent.
5/50
Accessors & Mutators
• Accessor method is used to return the
variables. The method name should start with
“get” and followed by property name with the
first character as capital.
• Example
6/50
public String getName ()
{
return name;
}
Why use Accessors
• Providing single points of update. The single
points of update for each attribute, making it
easier to modify and to test.
• Controlling access to attributes.
• Enabling lazy initialization. Lazy initialization
means the value of an attribute is initialized
(set) when it is first accessed.
• Reducing coupling between a subclass and its
super classes.
• Encapsulating changes to attributes
7/50
Mutators
• A Mutator is a method used to add/update
the value for the property.
• It should start with “set” followed by property
name with the first character as capital. It
should not return anything.
• Example of the Mutator
8/50
public void setName(String name)
{
this.name=name;
}
Types of JavaBeans
• Java Beans are classified into three types,
– Session Beans,
– Entity Beans,
– Message Driven Beans or Message Beans.
9/50
Session Beans
• It is used to Performs a task for a client .
• Session Bean is created by a customer and its
duration is only for the signal client server
session.
• The functions has performed by this bean is
calculations or database access, for the client.
• Session bean can be transactional, because it
is not recoverable.
10/50
Session Beans – Contd;
• Session Beans further classified into two
types
11/50
Stateless Session: The stateless
Session Beans has no connection
with informal state is a
distributed object. It allows the
parallel accessing of Beans.
Stateful Session: The Stateful
Session bean has a connection
with informal state, but with
very limited access to the
customer for Beans.
Entity Beans
• The Entity is used to represent a business
entity object that exists in persistent storage.
• It is recognized by a main key, if the container
is hosted by entity bean crashes, the bean will
destroy the remote reference.
12/50
Message Bean
• Message bean is used to act as a listener for
JMS (Java Message Service).
• It is similar to Session bean except the
respond to JMS.
• It will process the messages asynchronously.
• It processes the messages from multiple
clients.
13/50
Creating Java Bean
• Always a bean should contain properties and accessor
& mutators for those properties.
• If there are no properties in bean, then there is no
need for accessors and mutators.
• For some cases the bean just used as a class for
encapsulation (i.e.) business logic. Such a bean may or
may not have a visual representation.
• The Tomcat server searches for any classes in
c:tomcatwebappsrootweb-infclasses folder.
• Create a subfolder under class’s folder and name it as
'java beans’.
14/50
Summary
• Batch processing is one of the advanced features in
JDBC. It is used to execute a batch of statements (like a
query or updates) in a single call by creating a group of
statements.
• The ResultSetMeta-Data is used to view the details in
the Result set.
• It is always not possible to know the number of
columns, data types of the columns and names of the
columns while retrieving data from the table.
ResultSetMetaData can be used to overcome this issue.
• A connection pool is used to overcome the effects of
the usage of database by many users without
disconnecting it. It creates a pool of Connection object
when the application server starts. 15/50
Summary
• A Transaction Management system reduces the
complexity of application development because it frees
the developer from the complex issues of failure
recovery and multi-user programming.
• JavaBeans is the one of major Reusable software
component developed by Sun Microsystems for the
Java. It is mainly used in the builder tool.
• Accessor method is used to return the variables. The
method name should start with “get” and followed by
property name with the first character as capital.
• A Mutator is a method used to add/update the value
for the property. Mutator methods should start with
“set” followed by property name with the first
character as capital. It should not return anything.
16

JAVA_BEAN.pptx

  • 1.
  • 2.
    JAVA BEANS • JavaBeansis the one of major Reusable software component developed by Sun Microsystems for the Java. It is mainly used in the builder tool. • JavaBeans is a platform-independent, component model written in JAVA language, which can be changed and customized. • Java Bean contains a public constructor with no arguments, properties and accessor/mutator methods for those properties. 2/50
  • 3.
    JAVA BEANS –Contd; • A JavaBeans is just a java class with the following requirements. – It has a public no-args constructor – It has 'set' and 'get' methods for its properties. – It may have any general functions. – If required it must be Serializable. 3/50
  • 4.
    JAVA BEANS Example– Contd; 4/50 Public class sampleBean { private String name; private int age; public sampleBean() { } public String getName() { ------------- } public void setName(String name){ this.name=name; } public String getAge(){ ------------- } public void setAge(String age){ this.age=age; } }
  • 5.
    JAVA BEANS -Advantages • Java Bean is the Re-usable component, simply we can call “Write once and use everywhere” concept • It is very simple and flexible to use. • Portable and platform independent. 5/50
  • 6.
    Accessors & Mutators •Accessor method is used to return the variables. The method name should start with “get” and followed by property name with the first character as capital. • Example 6/50 public String getName () { return name; }
  • 7.
    Why use Accessors •Providing single points of update. The single points of update for each attribute, making it easier to modify and to test. • Controlling access to attributes. • Enabling lazy initialization. Lazy initialization means the value of an attribute is initialized (set) when it is first accessed. • Reducing coupling between a subclass and its super classes. • Encapsulating changes to attributes 7/50
  • 8.
    Mutators • A Mutatoris a method used to add/update the value for the property. • It should start with “set” followed by property name with the first character as capital. It should not return anything. • Example of the Mutator 8/50 public void setName(String name) { this.name=name; }
  • 9.
    Types of JavaBeans •Java Beans are classified into three types, – Session Beans, – Entity Beans, – Message Driven Beans or Message Beans. 9/50
  • 10.
    Session Beans • Itis used to Performs a task for a client . • Session Bean is created by a customer and its duration is only for the signal client server session. • The functions has performed by this bean is calculations or database access, for the client. • Session bean can be transactional, because it is not recoverable. 10/50
  • 11.
    Session Beans –Contd; • Session Beans further classified into two types 11/50 Stateless Session: The stateless Session Beans has no connection with informal state is a distributed object. It allows the parallel accessing of Beans. Stateful Session: The Stateful Session bean has a connection with informal state, but with very limited access to the customer for Beans.
  • 12.
    Entity Beans • TheEntity is used to represent a business entity object that exists in persistent storage. • It is recognized by a main key, if the container is hosted by entity bean crashes, the bean will destroy the remote reference. 12/50
  • 13.
    Message Bean • Messagebean is used to act as a listener for JMS (Java Message Service). • It is similar to Session bean except the respond to JMS. • It will process the messages asynchronously. • It processes the messages from multiple clients. 13/50
  • 14.
    Creating Java Bean •Always a bean should contain properties and accessor & mutators for those properties. • If there are no properties in bean, then there is no need for accessors and mutators. • For some cases the bean just used as a class for encapsulation (i.e.) business logic. Such a bean may or may not have a visual representation. • The Tomcat server searches for any classes in c:tomcatwebappsrootweb-infclasses folder. • Create a subfolder under class’s folder and name it as 'java beans’. 14/50
  • 15.
    Summary • Batch processingis one of the advanced features in JDBC. It is used to execute a batch of statements (like a query or updates) in a single call by creating a group of statements. • The ResultSetMeta-Data is used to view the details in the Result set. • It is always not possible to know the number of columns, data types of the columns and names of the columns while retrieving data from the table. ResultSetMetaData can be used to overcome this issue. • A connection pool is used to overcome the effects of the usage of database by many users without disconnecting it. It creates a pool of Connection object when the application server starts. 15/50
  • 16.
    Summary • A TransactionManagement system reduces the complexity of application development because it frees the developer from the complex issues of failure recovery and multi-user programming. • JavaBeans is the one of major Reusable software component developed by Sun Microsystems for the Java. It is mainly used in the builder tool. • Accessor method is used to return the variables. The method name should start with “get” and followed by property name with the first character as capital. • A Mutator is a method used to add/update the value for the property. Mutator methods should start with “set” followed by property name with the first character as capital. It should not return anything. 16