<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=JavaBeans</id>
	<title>JavaBeans - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=JavaBeans"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=JavaBeans&amp;action=history"/>
	<updated>2026-04-09T17:32:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=JavaBeans&amp;diff=678962&amp;oldid=prev</id>
		<title>69.157.231.172: /* Code example */</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=JavaBeans&amp;diff=678962&amp;oldid=prev"/>
		<updated>2025-09-06T17:11:46Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Code example&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Computing technology developer by Sun Microsystems}}&lt;br /&gt;
{{Distinguish|Enterprise JavaBeans}}&lt;br /&gt;
{{multiple issues|&lt;br /&gt;
{{more citations needed|date=June 2016}}&lt;br /&gt;
{{how-to|date=October 2012}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
In computing based on the [[Java (programming language)|Java]] Platform, &amp;#039;&amp;#039;&amp;#039;JavaBeans&amp;#039;&amp;#039;&amp;#039; is a technology developed by [[Sun Microsystems]] and released in 1996, as part of [[Java Development Kit|JDK]] 1.1.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;beans&amp;#039; of JavaBeans are classes that encapsulate one or more [[Object (computer science)|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 [[Type introspection|introspection]]. This in turn allows the beans to be treated as [[Component-based software engineering|software components]], and to be manipulated visually by [[Integrated development environment|editors and IDEs]] without needing any initial configuration, or to know any internal implementation details.&lt;br /&gt;
&lt;br /&gt;
As part of the standardization, all beans must be [[Serialization|serializable]], have a [[nullary constructor|zero-argument constructor]], and allow access to properties using [[Mutator method|getter and setter methods]].&lt;br /&gt;
&lt;br /&gt;
==Features==&lt;br /&gt;
;Introspection&lt;br /&gt;
: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.&lt;br /&gt;
;Properties&lt;br /&gt;
:A property is a subset of a Bean&amp;#039;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.&lt;br /&gt;
;Customization&lt;br /&gt;
:A customizer can provide a step-by-step guide that the process must follow to use the component in a specific context.&lt;br /&gt;
;Events&lt;br /&gt;
:Beans  may  interact with  the EventObject EventListener model.{{clarify|date=May 2020}}&lt;br /&gt;
;Persistence&lt;br /&gt;
:Persistence is the ability to save the current state of a Bean, including the values of a Bean&amp;#039;s properties and instance variables, to nonvolatile storage and to retrieve them at a later time.&lt;br /&gt;
;Methods&lt;br /&gt;
:A Bean should use [[Mutator method#Java example|accessor methods]] to [[Encapsulation (computer programming)|encapsulate]] the properties. A Bean can provide other methods for business logic not related to the access to the properties.&lt;br /&gt;
&lt;br /&gt;
== Advantages ==&lt;br /&gt;
&lt;br /&gt;
* The properties, events, and methods of a bean can be exposed to another application.&lt;br /&gt;
* A bean may register to receive events from other objects and can generate events that are sent to those other objects. {{citation needed|date=January 2023}}&lt;br /&gt;
* Auxiliary software can be provided to help configure a bean. {{citation needed|date=January 2023}}&lt;br /&gt;
*The configuration settings of a bean can be saved to persistent storage and restored. {{citation needed|date=January 2023}}&lt;br /&gt;
&lt;br /&gt;
== Disadvantages ==&lt;br /&gt;
* A class with a [[nullary constructor|zero-argument constructor]] is subject to being instantiated in an invalid state.&amp;lt;ref name=&amp;quot;Bloch&amp;quot;&amp;gt;{{cite book|last1=Bloch|first1=Joshua|authorlink1=Joshua Bloch|title=Effective Java|date=2008|publisher=Addison-Wesley|isbn=978-0-321-35668-0|page=[https://archive.org/details/effectivejava00bloc_0/page/13 13]|edition=Second|url-access=registration|url=https://archive.org/details/effectivejava00bloc_0/page/13}}&amp;lt;/ref&amp;gt; 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.&lt;br /&gt;
* JavaBeans are inherently mutable and so lack the advantages offered by [[immutable objects]].&amp;lt;ref name=&amp;quot;Bloch&amp;quot;/&amp;gt;&lt;br /&gt;
* 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]].&lt;br /&gt;
&lt;br /&gt;
== JavaBeans API ==&lt;br /&gt;
&lt;br /&gt;
The JavaBeans functionality is provided by a set of classes and interfaces in the &amp;lt;code&amp;gt;java.beans&amp;lt;/code&amp;gt; package.&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Interface !! Description&lt;br /&gt;
|-&lt;br /&gt;
| AppletInitializer || Methods in this interface are used to initialize Beans that are also [[Java applet|applet]]s.&lt;br /&gt;
|-java&lt;br /&gt;
| BeanInfo || This interface allows the designer to specify information about the events, methods and properties of a Bean.&lt;br /&gt;
|-&lt;br /&gt;
| Customizer || This interface allows the designer to provide a graphical user interface through which a bean may be configured.&lt;br /&gt;
|-&lt;br /&gt;
| DesignMode || Methods in this interface determine if a bean is executing in design mode.&lt;br /&gt;
|-&lt;br /&gt;
| ExceptionListener || A method in this interface is invoked when an exception has occurred.&lt;br /&gt;
|-&lt;br /&gt;
| PropertyChangeListener || A method in this interface is invoked when a bound property is changed.&lt;br /&gt;
|-&lt;br /&gt;
| PropertyEditor || Objects that implement this interface allow the designer to change and display property values.&lt;br /&gt;
|-&lt;br /&gt;
| VetoableChangeListener || A method in this interface is invoked when a Constrained property is changed.&lt;br /&gt;
|-&lt;br /&gt;
| Visibility || Methods in this interface allow a bean to execute in environments where the GUI is not available.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== JavaBean conventions ==&lt;br /&gt;
In order to function as a JavaBean [[Class (computer science)|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.&lt;br /&gt;
&lt;br /&gt;
The required conventions are as follows:&lt;br /&gt;
&lt;br /&gt;
* The class must have a public [[default constructor]] (with no arguments). This allows easy instantiation within editing and activation frameworks.&lt;br /&gt;
* The class [[property (programming)|properties]] must be accessible using &amp;#039;&amp;#039;get&amp;#039;&amp;#039;, &amp;#039;&amp;#039;set&amp;#039;&amp;#039;, &amp;#039;&amp;#039;is&amp;#039;&amp;#039; (can be used for boolean properties instead of get), &amp;#039;&amp;#039;to&amp;#039;&amp;#039;  and other methods (so-called [[Accessor|accessor methods]] and [[mutator method]]s) according to a standard [[naming conventions (programming)|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.&lt;br /&gt;
* The class should be [[Serialization#Programming language support|serializable]]. (This allows applications and frameworks to reliably save, store, and restore the bean&amp;#039;s state in a manner independent of the [[Virtual machine|VM]] and of the platform.)&lt;br /&gt;
&lt;br /&gt;
===Code example===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=Java&amp;gt;&lt;br /&gt;
package org.wikipedia.players;&lt;br /&gt;
&lt;br /&gt;
import java.io.Serializable;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
public class PersonBean implements Serializable {&lt;br /&gt;
    /** Properties **/&lt;br /&gt;
    private boolean deceased = false;&lt;br /&gt;
&lt;br /&gt;
    private List&amp;lt;String&amp;gt; list;&lt;br /&gt;
&lt;br /&gt;
    /** Property &amp;quot;name&amp;quot;, readable/writable. */&lt;br /&gt;
    private String name = null;&lt;br /&gt;
&lt;br /&gt;
    /** No-arg constructor (takes no arguments). */&lt;br /&gt;
    public PersonBean() {&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public List&amp;lt;String&amp;gt; getList() {&lt;br /&gt;
        return list;&lt;br /&gt;
    }&lt;br /&gt;
	&lt;br /&gt;
    public void setList(final List&amp;lt;String&amp;gt; list) {&lt;br /&gt;
        this.list = list;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Getter for property &amp;quot;name&amp;quot;.&lt;br /&gt;
     */&lt;br /&gt;
    public String getName() {&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Setter for property &amp;quot;name&amp;quot;.&lt;br /&gt;
     *&lt;br /&gt;
     * @param value&lt;br /&gt;
     */&lt;br /&gt;
    public void setName(final String value) {&lt;br /&gt;
        this.name = value;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Getter for property &amp;quot;deceased&amp;quot;&lt;br /&gt;
     * Different syntax for a boolean field (is vs get)&lt;br /&gt;
     */&lt;br /&gt;
    public boolean isDeceased() {&lt;br /&gt;
        return deceased;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Setter for property &amp;quot;deceased&amp;quot;.&lt;br /&gt;
     * @param value&lt;br /&gt;
     */&lt;br /&gt;
    public void setDeceased(boolean value) {&lt;br /&gt;
        deceased = value;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;lt;u&amp;gt;&amp;lt;code&amp;gt;TestPersonBean.java&amp;lt;/code&amp;gt;&amp;lt;/u&amp;gt;&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=Java&amp;gt;&lt;br /&gt;
package org.wikipedia.players;&lt;br /&gt;
&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
&lt;br /&gt;
import org.wikipedia.players.PersonBean;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Class &amp;quot;TestPersonBean&amp;quot;.&lt;br /&gt;
 */&lt;br /&gt;
public class TestPersonBean {&lt;br /&gt;
    /**&lt;br /&gt;
     * Tester method &amp;quot;main&amp;quot; for class &amp;quot;PersonBean&amp;quot;.&lt;br /&gt;
     *&lt;br /&gt;
     * @param arguments&lt;br /&gt;
     */&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        final PersonBean person = new PersonBean();&lt;br /&gt;
&lt;br /&gt;
        person.setName(&amp;quot;Bob&amp;quot;);&lt;br /&gt;
        person.setDeceased(false);&lt;br /&gt;
        person.setList(new ArrayList&amp;lt;String&amp;gt;());&lt;br /&gt;
&lt;br /&gt;
        // Output: &amp;quot;Bob is [alive]&amp;quot;&lt;br /&gt;
        System.out.printf(&amp;quot;%s is %s%n&amp;quot;, person.getName(), person.isDeceased() ? &amp;quot; [deceased]&amp;quot; : &amp;quot; [alive]&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jsp:useBean id=&amp;quot;person&amp;quot; class=&amp;quot;org.wikipedia.players.PersonBean&amp;quot; scope=&amp;quot;page&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;jsp:setProperty name=&amp;quot;person&amp;quot; property=&amp;quot;*&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
        Name: &amp;lt;jsp:getProperty name=&amp;quot;person&amp;quot; property=&amp;quot;name&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
        Deceased? &amp;lt;jsp:getProperty name=&amp;quot;person&amp;quot; property=&amp;quot;deceased&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;&lt;br /&gt;
        &amp;lt;form name=&amp;quot;beanTest&amp;quot; method=&amp;quot;POST&amp;quot; action=&amp;quot;testPersonBean.jsp&amp;quot;&amp;gt;&lt;br /&gt;
            Enter a name: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;name&amp;quot; size=&amp;quot;50&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
            Choose an option:&lt;br /&gt;
            &amp;lt;select name=&amp;quot;deceased&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;option value=&amp;quot;false&amp;quot;&amp;gt;Alive&amp;lt;/option&amp;gt;&lt;br /&gt;
                &amp;lt;option value=&amp;quot;true&amp;quot;&amp;gt;Dead&amp;lt;/option&amp;gt;&lt;br /&gt;
            &amp;lt;/select&amp;gt;&lt;br /&gt;
            &amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Test the Bean&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;/form&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Software package (disambiguation)|Software packaging]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist|2}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://download.oracle.com/javase/tutorial/javabeans/ Oracle&amp;#039;s JavaBeans tutorials]&lt;br /&gt;
* [http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html JavaBeans specification]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--Categories--&amp;gt;&lt;br /&gt;
[[Category:Java platform]]&lt;br /&gt;
[[Category:Articles with example Java code]]&lt;br /&gt;
[[Category:Architectural pattern (computer science)]]&lt;br /&gt;
[[Category:Software design patterns]]&lt;/div&gt;</summary>
		<author><name>69.157.231.172</name></author>
	</entry>
</feed>