Articles

POJO in java

POJO in java

POJO in java refers to 'Plain Old Java Object'.

The term POJO was first used by Martin Fowler, Josh Mackenzie and Rebecca Parsons.

 

POJO is simply 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, 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;
	}

}

 


Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com
Page Views : 385    Published Date :May 09,2019   Author :rajneesh
Please Share this page

Popular Articles

Loading...
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn moreGot it!