112

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?

Abhijith K
  • 3,090
  • 4
  • 19
  • 43
Siva
  • 3,227
  • 7
  • 28
  • 34

3 Answers3

152
  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
bouvierr
  • 3,399
  • 3
  • 26
  • 28
Kumar Vivek Mitra
  • 32,904
  • 6
  • 47
  • 76
  • 1
    I heard except no-argument constructor both pojo and bean are same right ? – Siva Sep 21 '12 at 03:08
  • java bean, implement Serializable means every time we must implement Serializable manually ? – Siva Sep 21 '12 at 03:27
  • A public no-argument constructor: I think every class has its own no-argument constructor if am correct, why you specified only for bean only ? sorry if am wrong am fresher. – Siva Sep 21 '12 at 03:29
  • if you did not specify any constructor for a class then only java will create no-argument constructor implicitly. – pathe.kiran Jan 10 '18 at 16:54
  • So all normal Java classes are POJOs? – firstpostcommenter Jan 16 '18 at 10:12
  • 1
    @firstpostcommenter It might be useful to get a description of what POJO is from the [person who coined the term](https://www.martinfowler.com/bliki/POJO.html). ("encoding business logic into regular java objects rather than using Entity Beans"). In other words, POJO was a name to given to describe "plain old java objects" *in order to* contrast Java beans. POJOs are domain/business objects specific, so not necessarily all Java classes are POJOs – THIS USER NEEDS HELP Apr 12 '18 at 23:15
29

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.

Kasun Siyambalapitiya
  • 3,407
  • 7
  • 33
  • 55
simap
  • 1,560
  • 1
  • 13
  • 9
8

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.

Nandkumar Tekale
  • 15,514
  • 7
  • 56
  • 85