bean就是一般的类,要使用bean只需要将方法的命名规则符合bean规范即可,属性用setXXX和getXXX来体现,还有event之类的都是通过方法的命名方法来确定的,所以bean是类的特殊化。你可以把所有的类当作bean那是没有问题的。据体规范,请参考JavaBean,不过不要和Enterprise JavaBean混在一起啊,他们的差别可大了。

解决方案 »

  1.   

    希望你不介意对JavaBeans概念的Sun的英文解释,最主要是下面的第一段,JavaBeans的定义。
    The JavaBeans API makes it possible to write component software in the Java programming language. Components are self-contained, reusable software units that can be visually composed into composite components, applets, applications, and servlets using visual application builder tools. JavaBean components are known as Beans. Components expose their features (for example, public methods and events) to builder tools for visual manipulation. A Bean's features are exposed because feature names adhere to specific design patterns. A "JavaBeans-enabled" builder tool can then examine the Bean's patterns, discern its features, and expose those features for visual manipulation. A builder tool maintains Beans in a palette or toolbox. You can select a Bean from the toolbox, drop it into a form, modify it's appearance and behavior, define its interaction with other Beans, and compose it and other Beans into an applet, application, or new Bean. All this can be done without writing a line of code. The following list briefly describes key Bean concepts, and gives the chapter in the JavaBeans specification where you can read a complete description. Builder tools discover a Bean's features (that is, its properties, methods, and events) by a process known as introspection. Beans support introspection in two ways: 
    By adhering to specific rules, known as design patterns, when naming Bean features. The Introspector class examines Beans for these design patterns to discover Bean features. The Introspector class relies on the core reflection API. The trail The Reflection API is an excellent place to learn about reflection. 
    By explicitly providing property, method, and event information with a related Bean Information class. A Bean information class implements the BeanInfo interface. A BeanInfo class explicitly lists those Bean features that are to be exposed to application builder tools. 
    Chapter 8 of the JavaBeans API Specification discusses introspection, design patterns, and BeanInfo objects. Properties are a Bean's appearance and behavior characteristics that can be changed at design time. Builder tools introspect on a Bean to discover its properties, and expose those properties for manipulation. Chapter 7 of the JavaBeans API Specification discusses properties. Beans expose properties so they can be customized at design time. Customization is supported in two ways: By using property editors, or by using more sophisticated Bean customizers. Chapter 9 of the JavaBeans API Specification discusses Bean customization. Beans use events to communicate with other Beans. A Bean that wants to receive events (a listener Bean) registers its interest with the Bean that fires the event (a source Bean). Builder tools can examine a Bean and determine which events that Bean can fire (send) and which it can handle (receive). Chapter 6 of the JavaBeans API Specification discusses events. Persistence enables Beans to save and restore their state. Once you've changed a Beans properties, you can save the state of the Bean and restore that Bean at a later time, property changes intact. JavaBeans uses Java Object Serialization to support persistence. Chapter 5 of the JavaBeans API Specification discusses persistence. A Bean's methods are no different than Java methods, and can be called from other Beans or a scripting environment. By default all public methods are exported. 
    Although Beans are designed to be understood by builder tools, all key APIs, including support for events, properties, and persistence, have been designed to be easily read and understood by human programmers as well. 
    作为尝试你可以参考一下建立一个简单的JavaBeans的例子,希望你有一个可视化的集成编程环境,比如JBuilder:
    http://java.sun.com/docs/books/tutorial/javabeans/writingbean/index.html
      

  2.   

    JavaBean和Enterprise JavaBean的差别是什么呢?还有,既然bean较之一般的类只是“bean只需要将方法的命名规则符合bean规范即可,属性用setXXX和getXXX来体现,还有event之类的都是通过方法的命名方法来确定的”,那还要它做什么呢?
      

  3.   

    bean要符合组件化开发的规范,而类么可以自由点。
      

  4.   

    JavaBeans同Class或者类库的差别好似VC中的MFC同VB中的Component/Control。两者相差实在太大,并非仅仅是规范的问题。理解这一点,自己做一个完整的JavaBeans就会很清楚了。
      

  5.   

    Bean封装了对象的属性和方法。
    给你一个javaBean的例子:Student.classpackage com;public class Student {
        private String sNo ;
    private String sName ;
    private String sSex ;
        private int iAge ;public Student() {
    init();
    }private void init() {
         sNo = "" ;
     sName ="" ;
     sSex ="" ;
         iAge =0 ;
    }public String getsNo(){
    return sNo ;
    }public String getsName(){
    return sName ;
    }public String getsSex(){
    return sSex ;
    }public int getiAge(){
    return iAge ;
    }public void setsNo(String t_sNo){
    sNo = t_sNo ;
    }public void setsName(String t_sName){
    sName = t_sName ;
    }public void setsSex(String t_sSex){
    sSex = t_sSex ;
    }public void setiAge(int t_iAge){
    iAge = t_iAge ;
    }
    public Student[] getStudents(int iNum){
    Student[] aStudents = new Student[iNum];
        for(int i=0;i<iNum;i++){
            Student oStudents = new Student();
            oStudents.setsNo("NO_"+i) ;
            oStudents.setsName("Name_"+i) ;
            oStudents.setsSex("Sex_"+i) ;
            oStudents.setiAge(i*10) ;
            aStudents[i] = oStudents ;
        }
    return  aStudents ;
    }}student.jsp<%@page contentType="text/html;charset=gb2312"%>
    <%
    com.Student aStudent[] = null ;
    aStudent = new com.Student().getStudents(10) ;
    if (aStudent!=null)
    for (int i=0 ;i<aStudent.length;i++){
    out.println(i+"-----------------<br>") ;
    out.println(aStudent[i].getsNo()+"<br>") ;
    out.println(aStudent[i].getsName()+"<br>") ;
    out.println(aStudent[i].getsSex()+"<br>") ;
    out.println(aStudent[i].getiAge()+"<br>") ;
     }

    %>
      

  6.   

    随便一个农民做的class,现在都叫做bean了!以前bean主要用于图形控件方面的开发,有严格的规范!
    现在用在server端开发后,就被用烂了,普通的类都可以称其为bean!