POJO (Plain Old Java Object)

POJOPlain Old Java Object — is a Java class that is not tied to any specific framework: no forced inheritance, no mandatory interfaces, no required annotations. Just fields, constructors and methods. The term was coined by Martin Fowler, Rebecca Parsons and Josh MacKenzie in 2000 in contrast to the heavyweight EJB 2 model.

Classic POJO

public class User {
    private Long id;
    private String name;
    private String email;

    public User() {}  // no-arg constructor for frameworks

    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public String getEmail() { return email; }
    public void setEmail(String email) { this.email = email; }
}

POJO vs JavaBean

A JavaBean is essentially a POJO that also conforms to the JavaBeans spec: no-arg constructor, private fields, public getters and setters, serializable. Every JavaBean is a POJO; not every POJO is a JavaBean.

POJO vs record

For data carriers, records (Java 16+) are the modern replacement for boilerplate POJOs:

public record User(Long id, String name, String email) {}

Records generate constructor, accessors, equals, hashCode and toString automatically. Most POJOs in new code should be records unless you need mutability.

Where POJOs are used

DTOs (data transfer objects), JPA entities, Jackson/Gson JSON mapping, Spring configuration beans. Any framework that uses reflection to populate field values needs at least a no-arg constructor, and most prefer setters or a canonical constructor.