Sobes.tech
Junior

Is Bean a class or an object?

sobes.tech AI

Answer from AI

A Bean in Java can be either a class or an object.

Bean as a class:

  • Usually a simple class with private fields and corresponding access methods (getA(), setB()).
  • Follows JavaBeans naming conventions:
    • Has a no-argument constructor.
    • Properties are accessible through get and set methods.
    • Boolean properties may use is instead of get.
    • Has public methods with no parameters.

Bean as an object:

  • An instance of a class created and managed by a framework (e.g., Spring, CDI).
  • Represents a specific instance of a component or service in an application.

Thus, "Bean" can refer to a specific style of writing a Java class or to a particular instance of that class managed by a container. In the context of frameworks, it is often referred to as a managed object.