What is POJO in Java?

What is POJO in Java?

POJO stands for Plain Old Java Object and would be used to describe the same things as a “Normal Class” whereas a JavaBean follows a set of rules.

Most commonly Beans use getters and setters to protect their member variables, which are typically set to private and have a no-argument constructor.

POJO stands for “Plain Old Java Object” — it’s a pure data structure that has fields with getters and possibly setters, and may override some methods from Object (e.g. equals) or some other interface like Serializable, but does not have a behavior of its own. It’s the Java equivalent of a C struct

class Point {

private double x;

private double y;

public double getX() { return x; }

ya public double getY() { return y; }

public void setX(double v) { x = v; }

ya public void setY(double v) { y = v; }

public boolean equals(Object other) {…}


As soon as you start adding methods that operate on points, like vector addition or complex multiplication, you no longer have a POJO.

What does “AAA” mean in title AAA games

how many religions are there full guide 

What is POJO in Java stands
What is POJO in Java stands

What is POJO in Java?

POJOs can have all of their methods defined automatically based on their field names and types — IDEs can do this for you, but the most elegant way is to use the annotations defined by Project Lombok:

  • @Data
  • class Point {
  • private double x;
  • private double y;
  • }
  • A2A

POJO stands for Plain Old Java Object, and would be used to describe the same things as a “Normal Class” whereas a JavaBean follows a set of rules. Most commonly Beans use getters and setters to protect their member variables, which are typically set to private and have a no-argument public constructor.

It refers to a Java object (instance of definition) that isn’t bogged down by framework extensions. For example, to receive messages from JMS, you need to write a class that implements the Message Listener interface.

POJO:- POJO is a Java object not bound by any restriction other than those forced by the Java Language Specification.

Properties of POJO

  1. All properties must public setter and getter methods
  2. Should not Extend prespecified classes.
  3. All instance variables should be private
  4. Should not Implement prespecified interfaces.
  5. Should not contain prespecified annotations.
  6. It may not have a no-argument constructor

Pokémon X ROM

Example of POJO

public class Data


private int id;

private String deptname;

return id;

private String date;

private String name;

this.id= id;

private String mdate;

private String mname;

public int getId() {


public void setId(int id) {


public String getDeptname() {

return deptname;


public void setDeptname(String deptname) {

this.deptname = deptname;


public String getDate() {

return date;


public void setDate(String date) {

this.date = date;


public String getName() {

return name;


public void setName(String name) {

this= name;


public String getMdate() {

return mdate;


public void setMdate(String mdate) {

this.mdate = mdate;


public String getMname() {

return mname;


public void setMname(String mname) {

this.mname = mname;

What is the order of the Lord of the Rings movies

Where do we use POJO in Java? What are the benefits of using it?

What is POJO Class?

  1. An ordinary Java class that does not extends or implement properties from any technology or framework related classes and interface are called a POJO class.
  2. POJO Class is used to represent data.
  3. POJO Class will contain only default constructors, private data members, and public setter and getter methods for every data member.
  4. Setter methods are used to set the value to the variable.
  5. Getter methods are used to get the value from the variable.
  6. In Hibernate this POJO class is used to store data and retrieve data. See this example
POJO in Java

Example of creating simple POJO Class-

What is Inverting amplifier

What is the POJO class in Hibernate?

JavaBeans are those with private attributes, which are accessible through public getter and setter methods, that conform to the JavaBean conventions. A JavaBean must implement Serializable and has a no-argument constructor. POJOs don’t have any of these restrictions.

POJOs in Hibernate are those which map their attributes with the corresponding columns of the relational database. Such a java object to table mapping is possible with the help of Hibernate as an ORM tool.

Transient & Persistent states:

Whenever an object of a POJO class is created then it will be in the Transient state

When the object is in a Transient state it doesn’t represent any row of the database, I mean not associated with any Session object, if we speak more we can say no relation with the database it’s just a normal object

If we modify the data of a POJO class object, when it is in a transient state then it doesn’t affect the database table

When the object is in a persistent state, then it represents one row of the database, if the object is in a persistent state then it is associated with the unique Session

if we want to move an object from persistent to detached state, we need to do either closing that session or need to clear the cache of the session

if we want to move an object from the persistent state into transient state then we need to delete that object permanently from the database

What is a text mail subscriber

How do I use POJO and Java Beans?

Its totally depend what kind of project implementation you are working.

One thing to remember : All JavaBeans are POJOs but not all POJOs are JavaBeans.

A JavaBean is a Java object that satisfies certain programming conventions:

  • the JavaBean class must implement either Serializable or Externalizable;
  • the JavaBean class must have a no-arg constructor;
  • all JavaBean properties must have a public setter and getter methods (as appropriate);
  • all JavaBean instance variables should be private.

POJO is an object which encapsulates Business Logic.

Java Beans can be used where we need to serialize or persist the data while POJO can be used for converting or populating of data from 1 form to another.

What is the difference between POJO and DAO?

POJO means Plain Old Java Objects which has member variables/fields and getters & setters method of those member variables/fields.

So that we can access those variables values in other classes with the help of the getXXX method and set/modify the value of any field with the setXXX method.

DAO is a Direct Access Object which communicates with the database layer and retrieves/inserts/updates data for service.

Forex. If we are having any functionality to retrieve the name of the students from the database then Class with class name Student will have fields/member variables student name, student number will be called POJO class wherein DAO class we will retrieve the name of students from the database. Hence query to retrieve data and database-related activities will be written in the DAO layer.

How to Make Fractionated Coconut Oil

How do I add dynamic attributes in POJO class?

Why dont you use a Map for that. It would be a lot easier.

Just create a hashmap in the class and add as many values as you want, dynamically.

 public Map<String, Object> attributes = new HashMap<>();//create an object

The way out is ‘Runtime Bytecode Modification’
It is technically possible but not feasible and you would not want to do that.
Because modifying the bytecode can be extremely messy and it (most likely) isn’t the approach you want.

However, if you decide to take this approach, I recommend a byte code manipulation library such as ASM.

How to change Spotify Picture 

What is POJO in Java stands
What is POJO in Java stands

What is the difference between JavaBean, EJB and POJO?

POJO means Plain Old Java Object. It doesn’t have to extend specific classes or definitions. It refers to a Java object (instance of definition) that isn’t bogged down by framework extensions

JavaBean is a POJO that is serializable has a no-argument constructor and allows access to properties using getter and setter methods

Enterprise JavaBeans (EJB) is a managed, server software for modular construction of enterprise software, and one of several Java APIs. EJB is a server-side software component that encapsulates the business logic of an application.

Here’s a good link also

Difference between Java Bean and Enterprise Java Beans?

Does planet fitness have showers And Lockers


  • It doesn’t have special restrictions other than those forced by Java language.
  • ho, It is a special POJO which has some restrictions.
  • It doesn’t provide much control over members.
  • It provides complete control of members.
  • can implement the Serializable interface.
  • It should implement the Serializable interface.
  • Fields can be accessed by their names.
  • yaa Fields are accessed only by getters and setters.
  • Fields can have any visibility.
  • Fields have only private visibility.
  • There can be a no-arg constructor.
  • It must have a no-arg constructor.

Searches related to What is POJO in Java

POJO class in java javatpoint

pojo class in java in hindi

comments for POJO class in java

how to create dynamic POJO class in java


POJO vs bean

POJO class with the list in java

java beans

What is the proper Tea time in Britain

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *