+ 3
What is beans in java?Why we use beans?
5 Antworten
+ 5
JavaBeans are classes that encapsulate many objects into a single object (the bean). All properties in java bean must be private with public getters and setter methods. These methods use to set and get the values.
public class Example {
private String name;
private int age;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
}
+ 2
Java Bean is a normal Java class which has private properties with its public getter and setter method.
Example:-
public class Sample
{
private String name;
public String getName()
{ return this.name; }
public void setName(String name)
{ this.name = name; }
}
//This is bean file :)
+ 2
Tysm bhavya
+ 2
Ty AJ
+ 1
Tysm puneet