What is java pojo class, java bean, normal class? [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 06:14:03

问题


Possible Duplicate:
Difference between DTO, VO, POJO, JavaBeans?

Hi please don\'t say my question is duplicate :-) I saw all questions but didn\'t understand the exact difference.

Can someone explain what is POJO, Bean, Normal Class in easy language?


回答1:


  1. Normal Class: A Java class

  2. Java Beans:

    • All properties private (use getters/setters)
    • A public no-argument constructor
    • Implements Serializable.
  3. Pojo: Plain Old Java Object is a Java object not bound by any restriction other than those forced by the Java Language Specification. I.e., a POJO should not have to

    • Extend prespecified classes
    • Implement prespecified interface
    • Contain prespecified annotations



回答2:


POJO stands for Plain Old Java Object, and would be used to describe the same things as a "Normal Class" whereas a JavaBean follows a set of rules. Most commonly Beans use getters and setters to protect their member variables, which are typically set to private and have a no-argument public constructor. Wikipedia has a pretty good rundown of JavaBeans: http://en.wikipedia.org/wiki/JavaBeans

POJO is usually used to describe a class that doesn't need to be a subclass of anything, or implement specific interfaces, or follow a specific pattern.




回答3:


POJO = Plain Old Java Object. It has properties, getters and setters for respective properties. It may also override Object.toString() and Object.equals().

Java Beans : See Wiki link.

Normal Class : Any java Class.



来源:https://stackoverflow.com/questions/12517905/what-is-java-pojo-class-java-bean-normal-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!