Is java bean
and java POJO
same thing or there are differences?
Asked
Active
Viewed 204 times
0
-
No, they aren't. Rules for Beans are stricter than for POJOs. – duffymo Oct 28 '14 at 09:05
-
A Java Bean must, Have a public default constructor & Be serializable – dneranjan Oct 28 '14 at 09:14
1 Answers
2
All JavaBeans are POJOs but not all POJOs are JavaBeans.
A JavaBean is a Java object that satisfies certain programming conventions:
the JavaBean class must implement either Serializable or Externalizable
the JavaBean class must have a no-arg constructor
all JavaBean properties must public setter and getter methods (as appropriate)
all JavaBean instance variables should be private

SonalPM
- 1,317
- 8
- 17
-
2very good answer. In addition to what you have said, some Java extension operations such as persistence and graphics favour JavaBeans over POJOs – ha9u63a7 Oct 28 '14 at 09:07
-
4100% identical with [this answer](http://stackoverflow.com/a/24886660/2817802) did you just copy it? – Baby Oct 28 '14 at 09:08
-
@TheQuickBrownFox: Nop.. This is what that is taught when You start learning Java........... ...... ............. The Java-Beanness of a POJO is that it's public attributes are all accessed via getters and setters that conform to the JavaBeans conventions. e.g. private String foo; public String getFoo(){...} public void setFoo(String foo){...}; – SonalPM Oct 28 '14 at 09:15
-