The Difference Between a JavaBean and a POJO



This site utilizes Google Analytics, Google AdSense, as well as participates in affiliate partnerships with various companies including Amazon. Please view the privacy policy for more details.

If you’ve programmed in Java for any amount of time, you’ll inevitably come across the terms bean, JavaBean, and POJO. What are they and how do they differ? Let’s start with some definitions:

JavaBean

According to Wikipedia, “JavaBeans are classes that encapsulate many objects into a single object (the bean).” Essentially, it’s a class with three characteristics:

  1. it’s serializable (i.e. implements java.io.Serializable)
  2. it has a no-argument constructor
  3. it allows access to its properties through the standard getters and setters.

Bean

A bean is a JavaBeans component, which is a reusable software component for Java. While I’m not 100% sure, it seems that “JavaBean” and “bean” are interchangeable.

POJO

POJO stands for Plain Old Java Object. Essentially, it’s the one of the simplest types of objects possible. There are no annotations, it extends no other classes, and implements no interfaces except perhaps a marker interface, such as java.io.Serializable. Finally, just like a JavaBean, it has a no-argument constructor, and allows access to its properties through the standard getters and setters.

Comparison

I like the following statement from StackOverflow:

All JavaBeans are POJOs but not all POJOs are JavaBeans.

Some people say a POJOs can’t implement java.io.Serializable, which would mean a JavaBean is not a POJO. I would argue that a POJO can implement java.io.Serializable, since implementing marker interfaces do not corrupt the “plainness” of a POJO.

Oh, and why is it called a bean? I have no source for this, but I believe it’s because beans are used to make coffee, and java is a type of coffee, so…

Further reading:

1 comment for The Difference Between a JavaBean and a POJO

  • Good article! simply explained the difference between JavaBean and a POJO for which i have been looking for, POJOs, however, are everywhere and the a backlash against the reasons for EJBs has led to extensive use of ‘lightweight’ Java growth.Thanks for sharing!

    Reply to This Thread

Leave a Reply

Note that comments won't appear until approved.