Content deleted Content added
NotAG on AWB (talk | contribs) replace {{manual}} with {{how-to}} per TfD |
|||
(20 intermediate revisions by 18 users not shown) | |||
Line 1:
{{Short description|Computing technology developer by Sun Microsystems}}
{{Distinguish|Enterprise JavaBeans}}
{{multiple issues|
{{
{{
}}
In computing based on the [[Java (programming language)|Java]] Platform, '''JavaBeans''' is a technology developed by [[Sun Microsystems]] and released in 1996, as part of [[Java Development Kit|JDK]] 1.1.
The 'beans' 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.
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]].
==Features==
;Introspection
:Introspection is a process of analyzing a Bean to determine its capabilities. This is an essential feature of the Java Beans
;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.
Line 21 ⟶ 24:
: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
== Advantages ==
* 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. {{citation needed|date=January 2023}}
* Auxiliary software can be provided to help configure a bean. {{citation needed|date=January 2023}}
*The configuration settings of a bean can be saved to persistent storage and restored. {{citation needed|date=January 2023}}
== Disadvantages ==
* A class with a [[nullary constructor|zero-argument constructor]] is subject to being instantiated in an invalid state.<ref name="Bloch">{{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}}</ref> 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]].<ref name="Bloch"/>
* 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 ==
The JavaBeans functionality is provided by a set of classes and interfaces in the <
{| class="wikitable sortable"
|-
Line 67 ⟶ 70:
* The class must have a public [[default constructor]] (with no arguments). This allows easy instantiation within editing and activation frameworks.
* The class [[property (programming)|properties]] must be accessible using ''get'', ''set'', ''is'' (can be used for boolean properties instead of get), ''to'' 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
* The class should be [[Serialization#Programming language support|serializable]]. (This allows applications and frameworks to reliably save, store, and restore the bean's state in a manner independent of the [[Virtual machine|VM]] and of the platform.)
Line 114 ⟶ 117:
/**
* Getter for property "deceased"
* Different syntax for a boolean field (is
*/
public boolean isDeceased() {
Line 178 ⟶ 181:
</html>
</syntaxhighlight>
== See also ==
* [[Software package (disambiguation)|Software packaging]]
==References==
Line 189 ⟶ 195:
[[Category:Java platform]]
[[Category:Articles with example Java code]]
[[Category:Architectural pattern (computer science)]]
[[Category:Software design patterns]]
|