views:

1207

answers:

1

I'm not sure about the difference. I'm using Hibernate and, in some books, they use JavaBean and POJO as an interchangeable term. I want to know if there is a difference, not just in the Hibernate context, but as general concepts.

+10  A: 

A JavaBean follows certain conventions. Getter/setter naming, having a public default constructor, being serialisable etc. See here for more details.

A POJO (plain-old-Java-object) isn't rigorously defined. It's a Java object that doesn't have a requirement to implement a particular interface or derive from a particular base class, or make use of particular annotations in order to be compatible with a given framework, and can be any arbitrary (often relatively simple) Java object.

Brian Agnew
Note that a JavaBean can be and usually is a POJO and many POJOs are actually JavaBeans.
Joachim Sauer
No, by the definition of POJO a Java Bean is *not* a POJO because to be considered a Java Bean a class must follow certain coding conventions (e.g. have a no-arg constructor, have methods that start with the words "get" and/or "set") or be distributed with a BeanInfo class.
Nat
Because these are *conventions*, I think you can successfully argue that a bean can be a POJO (e.g. you're not inheriting from a JavaBean interface or similar)
Brian Agnew
+1 for good answer
KLE
The JavaBeans spec fails to define a JavaBean other than very loosely as a "reusable software component" (or some such). It doesn't have to have a no-arg constructor, does not need methods starting with "get" or "set", does not need to be serialisable, doesn't even need to be a class.
Tom Hawtin - tackline