Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is java pojo class, java bean, normal class? [duplicate]

Possible Duplicate:
Difference between DTO, VO, POJO, JavaBeans?

Hi please don't say my question is duplicate :-) I saw all questions but didn't understand the exact difference.

Can someone explain what is POJO, Bean, Normal Class in easy language?

like image 913
Siva Avatar asked Sep 20 '12 17:09

Siva


People also ask

What is POJO and bean class in Java?

As we know that in Java POJO refers to the Plain old Java object.POJO and Bean class in Java shares some common features which are as follows − Both classes must be public i.e accessible to all. Properties or variables defined in both classes must be private i.e. can't be accessed directly.

What is the POJO class in Java?

POJO classes POJO stands for Plain Old Java Object. It is an ordinary Java object, not bound by any special restriction other than those forced by the Java Language Specification and not requiring any classpath. POJOs are used for increasing the readability and re-usability of a program.

What does POJO class contain?

Generally, a POJO class contains variables and their Getters and Setters. The POJO classes are similar to Beans as both are used to define the objects to increase the readability and re-usability.

What is a POJO in Spring?

POJO is short for Plain old java object, an application implemented in pojo way means the logic resides in POJO with little to no boilerplate code, thus it's very portable. An PoJo application can be ported from Spring to another container with little modification.


3 Answers

  1. Normal Class: A Java class

  2. Java Beans:

    • All properties private (use getters/setters)
    • A public no-argument constructor
    • Implements Serializable.
  3. Pojo: Plain Old Java Object is a Java object not bound by any restriction other than those forced by the Java Language Specification. I.e., a POJO should not have to

    • Extend prespecified classes
    • Implement prespecified interface
    • Contain prespecified annotations
like image 78
Kumar Vivek Mitra Avatar answered Oct 19 '22 18:10

Kumar Vivek Mitra


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. Wikipedia has a pretty good rundown of JavaBeans: http://en.wikipedia.org/wiki/JavaBeans

POJO is usually used to describe a class that doesn't need to be a subclass of anything, or implement specific interfaces, or follow a specific pattern.

like image 22
simap Avatar answered Oct 19 '22 16:10

simap


POJO = Plain Old Java Object. It has properties, getters and setters for respective properties. It may also override Object.toString() and Object.equals().

Java Beans : See Wiki link.

Normal Class : Any java Class.

like image 38
Nandkumar Tekale Avatar answered Oct 19 '22 17:10

Nandkumar Tekale