JavaBeans - wikipedia JavaBeans Not to be confused with Enterprise JavaBeans. This article has multiple issues. Please help improve it or discuss these issues on the talk page. ( Learn how and when to remove these template 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. ( June 2016 ) This article is written like a manual or guidebook. Please help rewrite this article from a descriptive, neutral point of view, and remove advice or instruction. ( October 2012 ) In computing based on the Java Platform, JavaBeans are classes that encapsulate many objects into a single object ( the bean ). They are serializable, have a zero - argument constructor, and allow access to properties using getter and setter methods. The name `` Bean '' was given to encompass this standard, which aims to create reusable software components for Java. Contents 1 Advantages 2 Disadvantages 3 JavaBeans API 4 JavaBean conventions 4.1 Code example 4.1. 1 Use in a JavaServer Page 5 References 6 External links 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. 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 A class with a nullary constructor is subject to being instantiated in an invalid state. 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 can not 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. 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 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 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 than one argument. 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 package player ; public class PersonBean implements java. io. Serializable ( / * * Properties * * / private boolean deceased = false ; private List list ; / * * Property < code > name < / code > ( note capitalization ) readable / writable. * / private String name = null ; / * * No - arg constructor ( takes no arguments ). * / public PersonBean ( ) ( ) public List getList ( ) ( return list ; ) public void setList ( final List list ) ( this. list = list ; ) / * * * Getter for property < code > name < / code > * / public String getName ( ) ( return name ; ) / * * * Setter for property < code > name < / code >. * * @ param value * / public void setName ( final String value ) ( this.name = value ; ) / * * * Getter for property `` deceased '' * Different syntax for a boolean field ( is v.s. get ) * / public boolean isDeceased ( ) ( return deceased ; ) / * * * Setter for property < code > deceased < / code >. * @ param value * / public void setDeceased ( final boolean value ) ( deceased = value ; ) ) TestPersonBean. java : import player. PersonBean ; / * * * Class < code > TestPersonBean < / code >. * / public class TestPersonBean ( / * * * Tester method < code > main < / code > for class < code > PersonBean < / code >. * * @ param arguments * / public static void main ( final String ( ) arguments ) ( final PersonBean person = new PersonBean ( ) ; person. setName ( `` Bob '' ) ; person. setDeceased ( false ) ; person. setList ( new ArrayList ( ) ) ; / / Output : `` Bob ( alive ) '' System. out. print ( person. getName ( ) ) ; System. out. println ( person. isDeceased ( ) ? `` ( deceased ) '' : `` ( alive ) '' ) ; ) ) Use in a JavaServer Page testPersonBean. jsp ; < % / / Use of PersonBean in a JSP. % > < jsp : useBean id = `` person '' class = `` player. PersonBean '' scope = `` page '' / > < jsp : setProperty name = `` person '' property = `` * '' / > < html > < body > Name : < jsp : getProperty name = `` person '' property = `` name '' / > < br / > Deceased ? < jsp : getProperty name = `` person '' property = `` deceased '' / > < br / > < br / > < form name = `` beanTest '' method = `` POST '' action = `` testPersonBean. jsp '' > Enter a name : < input type = `` text '' name = `` name '' size = `` 50 '' > < br / > Choose an option : < select name = `` deceased '' > < option value = `` false '' > Alive < / option > < option value = `` true '' > Dead < / option > < / select > < input type = `` submit '' value = `` Test the Bean '' > < / form > < / body > < / html > References ^ Jump up to : Bloch, Joshua ( 2008 ). Effective Java ( Second ed. ). Addison - Wesley. p. 13. ISBN 978 - 0 - 321 - 35668 - 0. External links Oracle 's JavaBeans tutorials JavaBeans specification Retrieved from `` https://en.wikipedia.org/w/index.php?title=JavaBeans&oldid=811563969 '' Categories : Java platform Hidden categories : Articles needing additional references from June 2016 All articles needing additional references Wikipedia articles needing style editing from October 2012 All articles needing style editing Articles with multiple maintenance issues Articles with example Java code Talk Contents About Wikipedia Català Čeština Deutsch Español Français 한국어 Interlingua Italiano עברית Magyar Nederlands 日本 語 Polski Português Русский کوردی Suomi ไทย Українська 中文 Edit links This page was last edited on 22 November 2017, at 12 : 44. Text is available under the Creative Commons Attribution - ShareAlike License ; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia ® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization. About Wikipedia

Question: a javabean or bean is a java class that
Answer: encapsulate many objects into a single object (the bean)