Difference among Model, javabean and POJO

15,312

Solution 1

If you're using the MVC architecture then the Model represents your domain: means your entities and it's not a java related term.
Your Models are represented in Java as Java Beans (best practice in Java EE).
A Java Bean is a normal Java class which implements the Serializable interface and have a parameterless constructor and have getters and setters for each field.

However POJO is just a denomination for objects not bound by any restriction other than those forced by the Java Language Specification (Wikipeadia). This is just for conventions sake and it's not strictly related to the MVC architecture.
Note that Java beans are POJOs implementing the Serializable interface.

Solution 2

Only difference is bean can be serialized.

From Java docs - http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html

Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.

While model is different thing which is dealing with your business logic.

you can refere below link

Programming difference between POJO and Bean

Solution 3

As a supplement, it's necessary to describe the intention of each item.

As defined from wiki,

The term "POJO" initially denoted a Java object which does not follow any of the major Java object models, conventions, or frameworks

Ideally speaking, a POJO is a Java object not bound by any restriction other than those forced by the Java Language Specification

Generally, a POJO doesn't dependent on any library, interface or annotation. Therefore, a POJO is more likely to be reused by different system.

Ok, so what is Java Bean and why we create this item?
The description from this link clarified it clear enough I think.

JavaBeans are classes that encapsulate many objects into a single object (the bean). They are serializable, have a zero-argument constructor, and allow access to properties using getter and setter methods.

Why we want Jave beans to behave like this?

  • The class must have a public default constructor (with no arguments).

This allows easy instantiation within editing and activation frameworks.

  • The class properties must be accessible using get, set, is (can be used for boolean properties instead of get), to and other methods (so-called accessor methods and mutator methods) according to a standard naming convention.

This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties. Setters can have one or more than one argument.

  • The class should be serializable.

This allows applications and frameworks to reliably save, store, and restore the bean's state in a manner independent of the VM and of the platform.

Generally, the model isn't compared with POJO or JaveBean cause it's quite a different item. Like what has mentioned by other answer, the model is generally a concept from MVC.

The model is the central component of the pattern. It is the application's dynamic data structure, independent of the user interface.[6] It directly manages the data, logic and rules of the application.

As you can see, POJO or JavaBean can be at model layer in MVC pattern but model layer but there are a lot more stuff in model layer, for example, the logic and rules of the application.

Share:
15,312
Varun
Author by

Varun

Updated on June 05, 2022

Comments

  • Varun
    Varun about 2 years

    I started learning MVC with spring. I have heard lot of time Bean, that contains setter and getter. Model is basically what data flows around, and Pojo which is same as Bean. But I am really confused in all this term and all this look same to me can you please explain the exact difference among all of them.

    JAVABEAN

    POJO

    MODEL