Pojo là gì
Bạn đang xem: Pojo là gì


A JavaBean follows certain conventions. Getter/setter naming, having a public default constructor, being serialisable etc. See JavaBeans Conventions for more details.
A POJO (plain-old-Java-object) isn"t rigorously defined. It"s a Java object that doesn"t have a requirement to implement a particular interface or derive from a particular base class, or make use of particular annotations in order to be compatible with a given framework, and can be any arbitrary (often relatively simple) Java object.
Share
Improve this answer
Follow
edited Apr 30, 2016 at 23:16
answered Sep 8, 2009 at 14:18

Brian AgnewBrian Agnew
261k3636 gold badges323323 silver badges430430 bronze badges
9
| Show 4 more comments
117
All JavaBeans are POJOs but not all POJOs are JavaBeans.
A JavaBean is a Java object that satisfies certain programming conventions:
the JavaBean class must implement either Serializable or Externalizable;the JavaBean class must have a public no-arg constructor;all JavaBean properties must have public setter and getter methods (as appropriate);all JavaBean instance variables should be private.Share
Improve this answer
Follow
edited Sep 8, 2017 at 6:39

Manu Manjunath
5,94122 gold badges3131 silver badges3131 bronze badges
answered Jul 22, 2014 at 11:52

nagapavannagapavan
1,17111 gold badge77 silver badges22 bronze badges
3
Add a comment |
26
According to Martin Fowler a POJO is an object which encapsulates Business Logic while a Bean (except for the definition already stated in other answers) is little more than a container for holding data and the operations available on the object merely set and get data.
The term was coined while Rebecca Parsons, Josh MacKenzie and I were preparing for a talk at a conference in September 2000. In the talk we were pointing out the many benefits of encoding business logic into regular java objects rather than using Entity Beans. We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it"s caught on very nicely.
http://www.martinfowler.com/bliki/POJO.html
Share
Improve this answer
Follow
answered Oct 12, 2015 at 7:23
SphygmomanometerSphygmomanometer
57555 silver badges1010 bronze badges
Add a comment |
10
Pojo - Plain old java object
pojo class is an ordinary class without any specialties,class totally loosely coupled from technology/framework.the class does not implements from technology/framework and does not extends from technology/framework api that class is called pojo class.
pojo class can implements interfaces and extend classes but the super class or interface should not be an technology/framework.
Examples :
1.
class ABC{----}ABC class not implementing or extending from technology/framework that"s why this is pojo class.
2.
Xem thêm: Tìm Hiểu Về Samsung Pay Hỗ Trợ Ngân Hàng Nào ? Samsung Pay Hỗ Trợ Thẻ Nào
class ABC extends HttpServlet{---}ABC class extending from servlet technology api that"s why this is not a pojo class.
3.
class ABC implements java.rmi.Remote{----}ABC class implements from rmi api that"s why this is not a pojo class.
4.
class ABC implements java.io.Serializable{---}this interface is part of java language not a part of technology/framework.so this is pojo class.
5.
class ABC extends Thread{--}here thread is also class of java language so this is also a pojo class.
6.
class ABC extends Test{--}if Test class extends or implements from technologies/framework then ABC is also not a pojo class because it inherits the properties of Test class.if Test class is not a pojo class then ABC class also not a pojo class.
7.
Xem thêm: Phạm Nhật Vượng Là Ai? Tiểu Sử Phạm Nhật Vượng Đầy Đủ Nhất Phạm Nhật Vượng
now this point is an exceptional case
Entityclass ABC{--}
Entity is an annotation given by hibernate api or jpa api but still we can call this class as pojo class.class with annotations given from technology/framework is called pojo class by this exceptional case.