This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "JavaBeans" – news · newspapers · books · scholar · JSTOR(June 2016) (Learn how and when to remove this message)
This article contains instructions, advice, or how-to content. Please help rewrite the content so that it is more encyclopedic or move it to Wikiversity, Wikibooks, or Wikivoyage.(October 2012)
(Learn how and when to remove this message)
In computing based on the Java Platform, JavaBeans is a technology developed by Sun Microsystems and released in 1996, as part of JDK 1.1.
The 'beans' of JavaBeans are classes that encapsulate one or more objects into a single standardized object (the bean). This standardization allows the beans to be handled in a more generic fashion, allowing easier code reuse and introspection. This in turn allows the beans to be treated as software components, and to be manipulated visually by editors and IDEs without needing any initial configuration, or to know any internal implementation details.
As part of the standardization, all beans must be serializable, have a zero-argument constructor, and allow access to properties using getter and setter methods.
Contents
1Features
2Advantages
3Disadvantages
4JavaBeans API
5JavaBean conventions
5.1Code example
6See also
7References
8External links
Features
edit
Introspection
Introspection is a process of analyzing a Bean to determine its capabilities. This is an essential feature of the Java Beans specification because it allows another application, such as a design tool, to obtain information about a component.
Properties
A property is a subset of a Bean's state. The values assigned to the properties determine the behaviour and appearance of that component. They are set through a setter method and can be obtained by a getter method.
Customization
A customizer can provide a step-by-step guide that the process must follow to use the component in a specific context.
Events
Beans may interact with the EventObject EventListener model.
Persistence
Persistence is the ability to save the current state of a Bean, including the values of a Bean's properties and instance variables, to nonvolatile storage and to retrieve them at a later time.
Methods
A Bean should use accessor methods to encapsulate the properties. A Bean can provide other methods for business logic not related to the access to the properties.
Advantages
edit
The properties, events, and methods of a bean can be exposed to another application.
A bean may register to receive events from other objects and can generate events that are sent to those other objects.
Auxiliary software can be provided to help configure a bean.
The configuration settings of a bean can be saved to persistent storage and restored.
Disadvantages
edit
A class with a zero-argument constructor is subject to being instantiated in an invalid state.[1] If such a class is instantiated manually by a developer (rather than automatically by some kind of framework), the developer might not realize that the class has been improperly instantiated. The compiler cannot detect such a problem, and even if it is documented, there is no guarantee that the developer will see the documentation.
JavaBeans are inherently mutable and so lack the advantages offered by immutable objects.[1]
Having to create getters for every property and setters for many, most, or all of them can lead to an immense quantity of boilerplate code.
JavaBeans API
edit
The JavaBeans functionality is provided by a set of classes and interfaces in the java.beans package.
Interface
Description
AppletInitializer
Methods in this interface are used to initialize Beans that are also applets.
BeanInfo
This interface allows the designer to specify information about the events, methods and properties of a Bean.
Customizer
This interface allows the designer to provide a graphical user interface through which a bean may be configured.
DesignMode
Methods in this interface determine if a bean is executing in design mode.
ExceptionListener
A method in this interface is invoked when an exception has occurred.
PropertyChangeListener
A method in this interface is invoked when a bound property is changed.
PropertyEditor
Objects that implement this interface allow the designer to change and display property values.
VetoableChangeListener
A method in this interface is invoked when a Constrained property is changed.
Visibility
Methods in this interface allow a bean to execute in environments where the GUI is not available.
JavaBean conventions
edit
In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behaviour. These conventions make it possible to have tools that can use, reuse, replace, and connect Java Beans.
The required conventions are as follows:
The class must have a public default constructor (with no arguments). This allows easy instantiation within editing and activation frameworks.
The class properties must be accessible using get, set, is (can be used for boolean properties instead of get), to and other methods (so-called accessor methods and mutator methods) according to 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. Setters can have one or more arguments.
The class should be serializable. (This allows applications and frameworks to reliably save, store, and restore the bean's state in a manner independent of the VM and of the platform.)
Code example
edit
packageplayer;publicclassPersonBeanimplementsjava.io.Serializable{/** Properties **/privatebooleandeceased=false;privateListlist;/** Property "name", readable/writable. */privateStringname=null;/** No-arg constructor (takes no arguments). */publicPersonBean(){}publicListgetList(){returnlist;}publicvoidsetList(finalListlist){this.list=list;}/** * Getter for property "name". */publicStringgetName(){returnname;}/** * Setter for property "name". * * @param value */publicvoidsetName(finalStringvalue){this.name=value;}Javabeans Tutorials: A javabean is a custom class which often represents real-world data and encapsulates private properties by public getter and setter methods. For example, User, Product, Order, etc.
Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website.
If you are using this website then its your own responsibility to understand the content of the website