POJO full form in java in 'Plain Old Java Object'.
The term POJO was first used by Martin Fowler, Josh Mackenzie and Rebecca Parsons.
POJO simply means a class that is not forced to implement any interface, extend any specific class, contain any pre-described annotation or follow any pattern due to forced restriction.
Any POJO class has following properties:
-
A java POJO class should be accessible to all the classes. It should be declared public.
-
The variables declared in java POJO class should be private.
-
A java POJO class should contain a default constructor.
-
A java POJO class must provide getter and setters which should be declared public to let outer world interact with it easily.
In our java development process, for example, we always interact with java POJO class if we work with java and hibernate. Because all the variables of java POJO (having getters and setters) are directly stored into the database with the help of ORM like Hibernate. But in that case the initial POJO class doesn't remain POJO as we use prespecified annotations on the variables to get it working with hibernate. We are not going in details about Hibernate here though we should be aware that java POJO plays a significant role in it.
Example of Java POJO
Given below is a simple example showing java pojo class:
public class POJOExample {
private int rollNo;
private String studentName;
private String fatherName;
private String course;
/**
* @return the rollNo
*/
public int getRollNo() {
return rollNo;
}
/**
* @param rollNo the rollNo to set
*/
public void setRollNo(int rollNo) {
this.rollNo = rollNo;
}
/**
* @return the studentName
*/
public String getStudentName() {
return studentName;
}
/**
* @param studentName the studentName to set
*/
public void setStudentName(String studentName) {
this.studentName = studentName;
}
/**
* @return the fatherName
*/
public String getFatherName() {
return fatherName;
}
/**
* @param fatherName the fatherName to set
*/
public void setFatherName(String fatherName) {
this.fatherName = fatherName;
}
/**
* @return the course
*/
public String getCourse() {
return course;
}
/**
* @param course the course to set
*/
public void setCourse(String course) {
this.course = course;
}
}
The above pojo class object can be easily converted to JSON, XML or other format.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Sonu Pandit
Technology geek, loves to write and share knowledge with the world. Having 10+ years of IT experience. B.Tech in Computer Science & Engineering
Page Views :
Published Date :
Jun 28,2020