This article from Wikipedia: Http://en.wikipedia.org/wiki/JavaBeans#JavaBean_conventions
JavaBeans is a reusable software component in the Java language, which is a special Java class that encapsulates many objects into an object (bean). The feature is serializable, providing a parameterless constructor that provides getter methods and setter methods to access the properties of the object.
Advantages:
- The bean can control whether its properties, events, and methods are exposed to other programs.
- The bean can receive events from other objects, or it can produce events to other objects.
- There is software available to configure the Bean.
- The attributes of the bean can be serialized for later reuse.
JavaBeans specification, to become a JavaBean class, you must follow specific specifications about naming, constructors, methods. With these specifications, you have the tools to use, reuse, replace, and connect JavaBeans.
The specifications are as follows:
- There is a public parameterless constructor.
- Properties can be accessed through get,set, is (can override get, use on Boolean properties) methods, or other methods that follow a specific naming convention.
- Serializable.
An example of a JavaBean code
Package player; public class Personbean implements java.io.Serializable { /** * Name Property (note case) */ private String name = N ull; Private Boolean deceased = false; /** parameterless Constructor (no parameters) */public Personbean () { } /** * Name Property getter Method */Public String getName () { return name; } /** * The setter method for the Name property * @param value * /public void SetName (final String value) { name = value; } /** * Deceased Property getter Method * Different form of Getter method for Boolean attribute (is used here instead of get) */Public Boolean isdeceased () { return deceased; } /** * Deceased Property setter Method * @param value * /public void setdeceased (final boolean value) { deceased = value; }}
Test examples:
Import player. Personbean; /** * <code>TestPersonBean</code> Classes */public class Testpersonbean { /** * Personbean class test method's main function * @param args */public static void Main (string[] ARGS) { Personbean person = new Personbean (); Person.setname ("Zhang San"); Person.setdeceased (false); Output: "Zhang San [alive]" System.out.print (Person.getname ()); System.out.println (person.isdeceased ()? "[Deceased]": "[Alive]");} }
Page reference and use JavaBean
<%//Use Personbean class%><jsp:usebean id= "person" class= "player in JSP. Personbean "scope=" page "/><jsp:setproperty name=" person "property=" * "/>
[Basic specification] JavaBeans specification