Advantages of Java Beans:-
1.It allows us to encapsulate many object into a single object called as Bean.
2.Java Beans add reusablity into the java program by maintaining a single encapsulating many data members and member function.
3.Java beans is a platform indenpent component that allow us to reuse the class object in our code.
4.Swing and AWT classes are javaBeans.
Below is the program to implement java beans
public class Employee{
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
In the Above program Employee class is a Java Beans that contains private data members that are being get and set by using public member functions
5.Exposer to other applications:- Property and methods of beans can be exposed directly to another application.
6.Registration to receive events:-We can generate events that can be sent to other objects
7.Ease of configuration:-We can easily save the configuration setting of a javaBeans to persistent storage.
8.We can easily port java beans to other platform.
Few Disadvantage:-
1.Due to mutabilty, which makes it not working with mutable objects.
2.Due to Setters and Getter for each property in a class may lead to a boilerplate code.
0 Comments