A POJO class in Java stands for Plain Old Java Object. It is a simple Java class that encapsulates only fields and their associated getter and setter methods. It is typically used to represent data in a structured way and has no business logic or behavior. Here is an example of a POJO class in Java:
Java
public class Person {
private String name;
private int age;
private String address;
public Person(String name, int age, String address) {
this.name = name;
this.age = age;
this.address = address;
}
// getter and setter methods
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
In the example above, the Person class has three fields: name, age, and address, each with their respective getter and setter methods. The constructor takes in the values of these fields as arguments and initializes the object.
This is a simple example, but POJO classes can be more complex with many more fields and methods. The key characteristic of a POJO class is that it does not have any dependencies or restrictions on its implementation, and it is solely responsible for representing data.
கருத்துரையிடுக