• Javabean


    from http://www.javatpoint.com/java-bean

    Java Bean

    A Java Bean is a java class that should follow following conventions:

    • It should have a no-arg constructor.
    • It should be Serializable.
    • It should provide methods to set and get the values of the properties, known as getter and setter methods.

    Why use Java Bean?

      According to Java white paper, it is a reusable software component. A bean encapsulates many objects into one object,

      so we can access this object from multiple places. Moreover, it provides the easy maintenance.

     Simple example of java bean class

    1. //Employee.java  
    2.   
    3. package mypack;  
    4. public class Employee implements java.io.Serializable{  
    5. private int id;  
    6. private String name;  
    7.   
    8. public Employee(){}  
    9.   
    10. public void setId(int id){this.id=id;}  
    11.   
    12. public int getId(){return id;}  
    13.   
    14. public void setName(String name){this.name=name;}  
    15.   
    16. public String getName(){return name;}  
    17.   
    18. }  
    How to access the java bean class? 
    1. package mypack;  
    2. public class Test{  
    3. public static void main(String args[]){  
    4.   
    5. Employee e=new Employee();//object is created  
    6.   
    7. e.setName("Arjun");//setting value to the object  
    8.   
    9. System.out.println(e.getName());  
    10.   
    11. }}  
  • 相关阅读:
    Redis5排序
    Redis5 常用命令
    Redis5事务 和Watch
    PHP7 ini 配置大全
    PHP 开发者大会
    go and git 代理
    laravel 记录sql语句
    Vue,laravel , laravels 项目在nginx 配置文件
    python selenium right click on an href and choose Save link as... on Chrome.
    selenium借助AutoIt识别上传(下载)详解
  • 原文地址:https://www.cnblogs.com/charles999/p/6588691.html
Copyright © 2020-2023  润新知