Bean Internals  «Prev  Next»
Lesson 16Creating properties
ObjectiveLearn how to create a property.

Create JavaBean Properties

Properties are created just like normal Java member variables.
The only thing that really distinguishes a property from a private member variable is that properties have at least one accessor method. Following is the declaration of an integer property named count, along with its accessor methods:

1) Running Programs 1 2) Running Programs 2 3) Running Programs 3

Program 1 Program 2 Program 2

Create Simple Properties

To add simple properties to a bean, add appropriate getXXX and setXXX methods (or isXXX and setXXX methods for a boolean property). The names of these methods follow specific rules called design patterns. These design pattern-based method names allow builder tools such as the NetBeans GUI Builder, to provide the following features:
  1. Discover a bean's properties
  2. Determine the properties' read/write attributes
  3. Determine the properties' types
  4. Locate the appropriate property editor for each property type
  5. Display the properties (usually in the Properties window)
  6. Alter the properties (at design time)
Count Text Property
In the next lesson, usage of a bean property will be discussed.