A plain Old Java Object is called the POJO class. POJO class has some points:
- The Java class without any specialities i.e. is a regular Java class.
- While developing this class we need not follow any serious rules.
- The Java class that does not extend from the technology or framework API class and does not implement technology or framework API interfaces is called the POJO class.
- Use of this class is improving the readability and reusability of the code.
- There is no restriction of modifiers of the properties in this class.
- This class is not mandatory for the 0-param constructor.
- This class uses getter() and setter() methods for transmitting and retrieving data from one layer to another in a real-time project.
- The POJO class should always be public.
- The POJO class should have the default constructor.
- The POJO class may contain the parameterized constructor if needed.
- Every Java Bean class is a POJO class.
Example of POJO class in Java
Some of the following examples of POJO classes in Java are mentioned below:
It is a Pojo class
It is also a Pojo class
Test, Demo classes are POJO classes
Test is a Pojo class
Test is not a Pojo class
Test is not a Pojo class
Creating a POJO class in Java
- In the above example we created a POJO class with the name “Person”. Properties of this class id, name, and mobileNo and modifiers of these properties are default, public and private respectively. This class contains a parameterized constructor to initialize these properties. This class also has the setter and getter method for each property for sending and retrieving data from classes. This is an example of a POJO class that uses every property in this Person class to make a POJO class.
- We can use the POJO class as a Model class when working on a real-time project. At that time we are sending data from Controller to Service to DAO and vice versa. POJO class helps to use reusability features in the code in real-world scenarios.
- We can use a private modifier for the properties of the POJO class when working on real-time projects.
Conclusion
This topic is explained What is a Pojo class? How can we identify which is the POJO class?