What is a JavaBean exactly?

后端 未结 19 1614
清酒与你
清酒与你 2020-11-22 01:55

I understood, I think, that a \"Bean\" is a Java class with properties and getters/setters. As much as I understand, it is the equivalent of a C struct. Is that true?

<
19条回答
  •  伪装坚强ぢ
    2020-11-22 02:41

    In practice, Beans are just objects which are handy to use. Serializing them means to be able easily to persist them (store in a form that is easily recovered).

    Typical uses of Beans in real world:

    • simple reusable objects POJO (Plain Old Java Objects)
    • visual objects
    • Spring uses Beans for objects to handle (for instance, User object that needs to be serialized in session)
    • EJB (Enterprise Java Beans), more complex objects, like JSF Beans (JSF is old quite outdated technology) or JSP Beans

    So in fact, Beans are just a convention / standard to expect something from a Java object that it would behave (serialization) and give some ways to change it (setters for properties) in a certain way.

    How to use them, is just your invention, but most common cases I enlisted above.

提交回复
热议问题