Last Updated : 23 Jul, 2025
POJO stands for Plain Old Java Object. In simple terms, we use POJO to make a programming model for declaring object entities. The classes are simple to use and do not have any restrictions as compared to Java Beans.
To read about POJO classes and Java Bean refer to the following article - POJO classes and Java Bean
POJO is handier as its best in readability and reusability. The only difference between java bean and POJO classes is POJOs don't have any restrictions other than java but java beans have.
Properties of POJO classesPOJO classes are used to encapsulate business logic and its members are treated as a database entity. The main motive of POJO classes is to define an object entity for hibernating.
Implementation:
Let us make an employee POJO class
A. File: Employee.java
Java
// Java Program to Illustrate Employee Class
// POJO class
// Importing required classes
import java.io.*;
// Class
class Employee {
// Private variables which are treated as an entity
private int empid;
private String name;
private int age;
// Getters and setters
// Getter
public int getEmpid() { return empid; }
// Setter
public void setEmpid(int empid) { this.empid = empid; }
// Getter
public String getName() { return name; }
// Setter
public void setName(String name) { this.name = name; }
// Getter
public int getAge() { return age; }
// Setter
public void setAge(int age) { this.age = age; }
}
Let's make a POJO class method and use them to set and get the data.
B. File: MainClass.java
Java
// Importing required classes
import java.io.*;
// Main class
class MainClass {
// Main driver method
public static void main(String[] args)
{
// Making a POJO class method to
// set and retrieve some values
employee emp = new employee();
// Setting the values with setters
emp.setEmpid(123);
emp.setName("Geek");
emp.setAge(21);
// Retrieving some values from getters
System.out.println("The employee ID is "
+ emp.getEmpid());
System.out.println("The name of the employee is "
+ emp.getName());
System.out.println("The age of the employee is "
+ emp.getAge());
}
}
Output:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4