A JavaBean is a Java class that should follow the following conventions:
Why use JavaBean?
According to Java white paper, it is a reusable software component. A bean encapsulates many objects into one object so that we can access this object from multiple places. Moreover, it provides easy maintenance.
Simple example of JavaBean class
How to access the JavaBean class?
To access the JavaBean class, we should use getter and setter methods.
Note: There are two ways to provide values to the object. One way is by constructor and second is by setter method.
A JavaBean property is a named feature that can be accessed by the user of the object. The feature can be of any Java data type, containing the classes that you define.
A JavaBean property may be read, write, read-only, or write-only. JavaBean features are accessed through two methods in the JavaBean's implementation class:
1. getPropertyName ()
For example, if the property name is firstName, the method name would be getFirstName() to read that property. This method is called the accessor.
2. setPropertyName ()
For example, if the property name is firstName, the method name would be setFirstName() to write that property. This method is called the mutator.
Advantages of JavaBean
The following are the advantages of JavaBean:/p>
Disadvantages of JavaBean
The following are the disadvantages of JavaBean: