Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference among Model, javabean and POJO

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

like image 556
Varun Avatar asked Mar 31 '15 10:03

Varun


People also ask

What is the difference between POJO and JavaBean?

Differences Between POJO and Java beans:POJO can have other than private fields whereas Java beans can only have private fields. POJO may or may not have a constructor whereas Java beans should have a no-argument constructor.

Is JavaBean a POJO?

Beans are special type of Pojos. There are some restrictions on POJO to be a bean. All JavaBeans are POJOs but not all POJOs are JavaBeans. Serializable i.e. they should implement Serializable interface.

What is the difference between POJO and entity?

I think there is no difference between between entity class and pojo class,if you annotate your pojo class by @ENTITY annotation that particular class will be considered as Entity class. every entity class is a pojo class because the have setter and getter method so you can get and set the properties of your entity.

Is model class POJO?

Typically a model class is a POJO because models are actually simple old fashioned java objects. But then you may write a POJO but not use it as a model.


1 Answers

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.

like image 83
Fourat Avatar answered Oct 11 '22 08:10

Fourat