The Difference Between a JavaBean and a POJO



Occasionally I may include affiliate links, which means I may get a commision if you purchase something via that link. Check out my privacy policy for more info.

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:

Related posts: