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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With