0% found this document useful (0 votes)
7 views7 pages

Javabeans Classes

JAVABEANS CLASSES

Uploaded by

Francis Martin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Javabeans Classes

JAVABEANS CLASSES

Uploaded by

Francis Martin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

JAVABEANS CLASSES.

What is JavaBeans?
-Are classes that encapsulate multiple
objects into single object.
It also helps in accessing these object
from multiple places. It contain several
elements like CONSTRUCTORS , GETTER
and SETTER methods. In Javabeans
the following conventions should be
followed.
i)CLASS DEFINITIONS: They are defined
as public classes.
ii)OPTIONAL: While not mandatory they
often implement Serializable interface to
allow object data to be converted into
stream of bytes for storage or
transmission.
iii) NO ARGUMENT
CONSTRUCTOR:
Javabeans must have a public
constructor that take no arguments.
iv) GETTER AND SETTER METHODS:
for
each private field there should be
corresponding public getter and setter
method.
-Getter methods retrieve the
value of a field.
-Setter methods modify the value
of a field.

Example of JAVABEAN
CLASS. File Name:
package mypack;
public class Student implements
java.io.Serializable{
private int id;
private String name;
public Student(){
public void set Id(int id){
this .id=id;
}
Public int getId(){
return id;
}
Public void setName(String name){
this.name=name;
}
public String getName(){
return name;}
}
HOW TO ACCESS THE
JAVABEAN CLASS
To access the javabean class we should
use the getter and setter methods
EXAMPLE:
File Name: Test.java
Package my pack;
Public class Test(
Public static void main(String[] args){
Student s=new Student();
s.setName(“TEACHER”);
System.out.println(e.getName());
}}
PROPERTIES OF SETTER METHODS
1.it must be public in nature
2.The return type should be void
3.it should take some argument

PROPERTIES OF GETTER
METHOD
1. It should be public in nature
2.The return type should not be void
3.it does not take any argument

BENEFITS OF USING JAVABEAN


1.REUSABILITY
Once javabean is created it can be used
across different application.It allows
developers to build upon existing
component and not from the scratch.
2. ENCAPSULATION
Encapsulates many object into one.It
helps in managing complexity by
exposing only necessary parts of the
functionality
3. CUSTOMIZATION
Javabeans can be customized easily
using property editors and customizers.
It allow developers to configure a bean
to fit their specific environment
4. EASE OF USE
Even for non-programmers they still can
use javabean to build their applications.
5.SECURITY
Javabeans provide security framework
that support features like signing and
authorization which can be critical for
applications that require high security

You might also like