JavaBean

format_list_bulleted Contenido keyboard_arrow_down
ImprimirCitar

The JavaBeans are a component model created by Sun Microsystems for building Java applications.

They are used to encapsulate several objects in a single object (the pod or Bean in English), to make use of a single object instead of several simpler ones.

The Sun Microsystems JavaBeans specification defines them as "reusable software components that can be manipulated visually in a build tool".

Despite many similarities, JavaBeans should not be confused with Enterprise JavaBeans (EJB), a server-side component technology that is part of Java EE.

JavaBean Conventions

To function as a JavaBean class, a class must obey certain conventions about method naming, construction, and behavior.

These conventions allow for tools that can use, reuse, replace, and plug in JavaBeans.

The required conventions are:

  • You must have a builder without arguments.
  • His class attributes must be private.
  • Its properties should be accessible through get and set methods that follow a standard nomenclature convention.
  • It must be serializable.

Structure

Within a JavaBean we can distinguish three parts:

  • Properties: The attributes it contains.
  • Methods: Methods are established get and set to access and modify the attributes.
  • Events: Allow to communicate with other JavaBeans.

Example

// Implementation of the Serializable interface of the java.io package public class PersonBean implements java.io.Serializable { // Each instance variable has a private access modifier. private String Name; private int Age; // Empty builder and without arguments. public PersonBean() { ! // Optional builder of a JavaBean. public PersonBean(String Name, int Age) { this.Name = Name; this.Age = Age; ! // Builder per copy (optional) public PersonBean(PersonBean personBean) { this.Name = personBean.getName(); this.Age = personBean.getEdad(); ! // For each property add a get and set method. public String getName() { return Name; ! public void set(String Name) { this.Name = Name; ! public int getEdad() { return Age; ! public void setEdad(int Age) { this.Age = Age; !!

Contenido relacionado

Hogwarts School of Witchcraft and Wizardry

The Hogwarts School of Witchcraft and Wizardry is a school of magic belonging to the universe of the Harry Potter book...

Monforte de la sierra

Monforte de la Sierra is a Spanish municipality and town in the province of Salamanca, in the autonomous community of Castilla y León. It is integrated into...

Back to the Future

Back to the Future is a 1985 American science fiction comedy film directed and written by Robert Zemeckis —Bob Gale also contributed as a screenwriter—...

Klaus kinski

Nikolaus Nakszynski also known as Klaus Kinski, was a German actor, nationalized American, closely linked to the director Werner...

10 (film)

10 is a 1979 American comedy film directed by Blake Edwards and starring Dudley Moore, Bo Derek, Julie Andrews, Robert Webber, Dee Wallace -Stone and Brian...
Más resultados...
Tamaño del texto:
undoredo
format_boldformat_italicformat_underlinedstrikethrough_ssuperscriptsubscriptlink
save