See Wikipedia for a few of the following:
JavaBeans refers to a class that conforms to certain criteria, and the name of the bean is used to cover this standard, which is designed to create reusable Java components.
Because beans are "inflexible" things, they can be stored durably and can be quickly implemented with assistive software.
The Bean has its own set of APIs.
JavaBean Conventions[edit]
In order to function as a JavaBean class, the object class must obey certain conventions about method naming, construction, and behaviour. These conventions make it possible to has tools that can use, reuse, replace, and connect Java Beans.
The required conventions is as follows:
- The class must has 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, are (can be used for Boolean properties Instead of get), and other methods (so-called accessor methods and mutator methods) according to a standard naming convent Ion. This allows easy automated inspection and updating of beans State within frameworks, many of which include custom editors F or various types of properties. Setters can has 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.)
example, 1 no parameter constructor 2getter, setter 3 implementation serialization
Packageplayer; Public classPersonbeanImplements java.io.Serializable {/*** Property <code>name</code> (note capitalization) readable/writable. */ PrivateString name =NULL; Private Booleandeceased =false; Privatelist List; PublicList getList () {returnlist; } Public voidsetlist (List list) { This. list=list; } /**No-arg Constructor (takes No arguments).*/ PublicPersonbean () {}/*** Getter for property <code>name</code>*/ PublicString GetName () {returnname; } /*** Setter for property <code>name</code>. * @paramvalue*/ Public voidSetName (FinalString value) {Name=value; } /*** Getter for property ' deceased ' * Different syntax for a Boolean field (is vs. get)*/ Public Booleanisdeceased () {returndeceased; } /*** Setter for property <code>deceased</code>. * @paramvalue*/ Public voidSetdeceased (Final Booleanvalue) {Deceased=value; }}
To use Personbean in a JSP page:
<%//Use of the 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" M Ethod= "POST" action= "testpersonbean.jsp" >Enter a name:<input type= "text" name= "name" size= "><br/>"Choose an option:<select name= "Deceased" > <option value= "false" >Alive</option> <option V Alue= "true" >Dead</option> </select> <input type= "Submit" value= "Test the Bean" > </form> </body>What is JavaBeans?