Sobes.tech
Junior — Middle

Explain what a Plain Old Java Object (POJO) class is and how it differs from other classes in Java.

sobes.tech AI

Answer from AI

POJO (Plain Old Java Object) is a simple Java class that does not depend on any special frameworks or libraries. It typically contains fields, getters and setters, constructors, and does not include business logic or annotations specific to frameworks.

Differences of POJO from other classes:

  • Does not inherit from specific classes or interfaces (e.g., EJB components).
  • Does not use special annotations or dependencies.
  • Easy to test and transfer.

Example of POJO:

public class User {
    private String name;
    private int age;

    public User() {}

    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; }
}

Thus, POJO is simply a data structure without additional logic and dependencies.