JavaBean

A JavaBean is a Java class. Like other Java classes, JavaBeans are reusable code. They are unique in their design because they encapsulate several objects into one. There are three conventions a JavaBean class must follow:

  • The constructor should not take any arguments
  • It must be serializable
  • It must contain mutator and accessor methods for its properties

Here is an example JavaBean class:

    public class MyBean implements java.io.Serializable     {      // instance variables        private int studentId;      private String studentName;      // no-argument constructor      public MyBean()       {        }        // mutator/setter       public void setStudentId(int theID)      {        this.studentId = theID;      }      // accessor/getter      public int getStudentId()      {        return studentId;      } // mutator/setter ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.