JavaBean

JavaBean

JavaBeans are reusable software components for Java that can be manipulated visually in a builder tool. Practically, they are classes written in the Java programming language conforming to a particular convention. They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects.

JavaBean conventions

In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behavior. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans.

The required conventions are:

* The class must have a no-argument public constructor. This allows easy instantiation within editing and activation frameworks.
* The class properties must be accessible using "get", "set", and other methods (so-called accessor methods), following a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties.
* The class should be serializable. This allows applications and frameworks to reliably save, store, and restore the bean's state in fashion that is independent of the VM and platform.

Because these requirements are largely expressed as conventions rather than by implementing interfaces, some developers view JavaBeans as Plain Old Java Objects that follow specific naming conventions.

JavaBean Example

// PersonBean.java

public class PersonBean implements java.io.Serializable { private String name; private boolean deceased;

// No-arg constructor (takes no arguments). public PersonBean() { }

// Property "name" (note capitalization) readable/writable public String getName() { return this.name; }

public void setName(String name) { this.name = name; }

// Property "deceased" // Different syntax for a boolean field (is vs. get) public boolean isDeceased() { return this.deceased; }

public void setDeceased(boolean deceased) { this.deceased = deceased;

// TestPersonBean.java

public class TestPersonBean { public static void main(String [] args) { PersonBean person = new PersonBean(); person.setName("Bob"); person.setDeceased(false);

// Output: "Bob [alive] " System.out.print(person.getName()); System.out.println(person.isDeceased() ? " [deceased] " : " [alive] ");

Adoption

AWT, Swing, and SWT, the major Java GUI toolkits, use JavaBeans conventions for their components. This allows GUI editors like the Eclipse Visual Editor or the NetBeans GUI Editor to maintain a hierarchy of components and to provide access to their properties via uniformly-named accessors and mutators.

See also

* Enterprise JavaBeans (an unrelated concept)
* Widgets
* Microsoft COM, a component implementation on Microsoft Windows.

External links

* [http://java.sun.com/products/javabeans/ Sun's JavaBeans product page]
* [http://java.sun.com/products/javabeans/learning/tutorial/index.html Sun's JavaBeans tutorials]


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • JavaBean — Desarrollador Sun Microsystems http://java.sun.com/... Información general Última versión estable …   Wikipedia Español

  • JavaBean — JavaBeans sind Software Komponenten für die Programmiersprache Java. JavaBeans entwickelten sich aus der Notwendigkeit heraus, GUI Klassen (AWT, Swing) einfach instanziieren (Reflexion) und übertragen (RMI) zu können. JavaBeans werden auch als… …   Deutsch Wikipedia

  • JavaBean — noun A software component written in Java …   Wiktionary

  • javabean — ● n. m. ►LANG Les grains de café en provenance de Java plaisaient beaucoup aux développeurs du langage. Les beans (ou Javabeans) sont des composants logiciels écrits en Java (et non pas la petite famille de Mr Bean) …   Dictionnaire d'informatique francophone

  • Javabean — n. small application in the Java language intended to perform defined tasks (used on the Internet for tasks such as calculating interest, updating weather forecasts, etc.) …   English contemporary dictionary

  • Enterprise JavaBean — Simple EJB2 Architecture Enterprise JavaBeans (EJB) is a managed, server side component architecture for modular construction of enterprise applications. The EJB specification is one of several Java APIs in the Java EE specification. EJB is a… …   Wikipedia

  • Enterprise JavaBean — wiederverwendbares ⇡ Modul einer auf der ⇡ Enterprise JavaBeans Architektur basierenden, in ⇡ Java geschriebenen Anwendungssoftware. Ein E.J. stellt innerhalb der betrieblichen Anwendungsdomäne ein Geschäftsobjekt, ein sog. Business Object (z.B.… …   Lexikon der Economics

  • Beans — JavaBeans sind Software Komponenten für die Programmiersprache Java. JavaBeans entwickelten sich aus der Notwendigkeit heraus, GUI Klassen (AWT, Swing) einfach instanziieren (Reflexion) und übertragen (RMI) zu können. JavaBeans werden auch als… …   Deutsch Wikipedia

  • JavaBeans — sind Software Komponenten für die Programmiersprache Java. JavaBeans entwickelten sich aus der Notwendigkeit heraus, GUI Klassen (AWT, Swing) einfach instanziieren (Reflexion) und übertragen (RMI) zu können. JavaBeans werden auch als Container… …   Deutsch Wikipedia

  • Java Beans — JavaBeans sind Software Komponenten für die Programmiersprache Java. JavaBeans entwickelten sich aus der Notwendigkeit heraus, GUI Klassen (AWT, Swing) einfach instanziieren (Reflexion) und übertragen (RMI) zu können. JavaBeans werden auch als… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”