Plain Old Java Object (English)

Přejít na: navigace, hledání
Tato stránka je dostupná také v češtině: Plain Old Java Object

POJO is an acronym for Plain Old Java Object. This term was first used by Martin Fowler, Rebecca Parsons and Josh Mackenzie in 2000 (Martin Fowler 2000). Plain Old Java Object represents simple class (or in other words a lightweight entity) on which no special requirements are enforced. It neither has to implement any interface nor it has to extend any class. These classes are simple, easy to read and easily maintainable. Possible requirements may include presence of a parameterless constructor or observance of getter/setter method conventions. POJO classes are used for example in Spring, JPA or EJB (since release 3.0).

Example of a POJO class:

//POJO class representing simple player entity.
public class Client { // beginning of the class
private Long id;
private String name;
private String address;
public Long getId() {
    return id;
public void setId(Long id) {;
public String getName() {
    return name; 
public void setName(String name) {;
public String getAddress() {
    return address;
public void setAddress(String adress) {
public String toString() {
    return "Clients ID is : " +id ;
public boolean equals(Object o) {
    if (o instanceof Client) {
      Client c = (Client) o;
      if ( return true;
    return false; 
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash +;
        return hash; }} // end of the class