Java Reference
In-Depth Information
JavaBeans have properties that are determined by the public methods in the class. These
special methods have the following properties:
The property methods begin with “set” and “get,” or “set” and “is” for boolean data
types. The set methods are referred to as mutator methods because they change the
property, and get methods are referred to as accessor methods because they return a
property.
The letter following the set or get is capitalized.
The property name is the name of method minus the set or get, with the first letter in
lowercase.
For example, suppose a class contains the following two methods:
public void setLastName(String s)
public String getLastName()
The name of the JavaBean property resulting from these two methods is lastName , and
the data type of the property is String . The parameter of the set method has to be the same
data type as the return value of the get method.
Let's take a look at the following Employee class example and see if you can determine
its JavaBeans properties:
1. import java.util.GregorianCalendar;
2.
3. public class Employee implements java.io.Serializable {
4. private String first, last;
5. private GregorianCalendar hireDate;
6. public double salary;
7. private boolean fullTime;
8.
9. public String getFirstName() {
10. return first;
11. }
12.
13. public void setLastName(String s) {
14. last = s;
15. }
16.
17. public String getLastName() {
18. return last;
19. }
20.
21. public GregorianCalendar getHireDate() {
22. return hireDate;
Search WWH ::




Custom Search