[Basic specification] JavaBeans specification

Source: Internet
Author: User
Tags base64 naming convention

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.