Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Bean, Java Bean and Enterprise Java Beans [duplicate]

I have read about EJB, Java Beans , however i still have doubts about what term "bean" in itself means?

A) Does the plain term "bean" exist in itself?

B) Now coming to Java Beans. As i read, it is just a plain POJO which follow some naming convention, and have getter and setters? However i have difficulty in understanding how does this convention make them as "reusable components", as i read in many posts including SO.

There are some SO posts similar to this, however it is different in that: I am asking if plan term "bean" exists; and how come java beans are reusable components.

Could someone please clarify this in simple terms.

like image 673
CuriousMind Avatar asked Sep 28 '22 11:09

CuriousMind


1 Answers

The plain term "bean" is frequently used as as a shortcut to JavaBean or Enterprise Java Bean (depending on the context). So, the term exists in the common language of programmers and it refers in general to reusable objects/components in Java.

JavaBean is a POJO class with specific naming conventions for getters and setters, true and not only that: it is usually an encapsulation of other objects (properties), is serialisable and with a zero-argument constructor. There is a complete specification developed by Sun (at that moment) about JavaBean. Sun defined it as "a reusable software component that can be manipulated visually in a builder tool". Moreover, in JavaBean Specification it is stated that:

Individual Java Beans will vary in the functionality they support, but the typical unifying features that distinguish a Java Bean are:

  • Support for “introspection” so that a builder tool can analyze how a bean works
  • Support for “customization” so that when using an application builder a user can customize the appearance and behaviour of a bean
  • Support for “events” as a simple communication metaphor than can be used to connect up beans
  • Support for “properties”, both for customization and for programmatic use.
  • Support for persistence,so that a bean can be customized in an application builder and then have its customized state saved away and reloaded later.

The essential part is that can be visually manipulates hence the need for getters/setters, events, zero-argument constructor (so that they can be externally instantiated), serialisable.

Check this link for more details: http://download.oracle.com/otn-pub/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/beans.101.pdf?AuthParam=1435694253_b87821c280430a0230bf8d22223c79d2

like image 186
iullianr Avatar answered Oct 13 '22 01:10

iullianr