Bean Internals  «Prev  Next»
Lesson 1

JavaBeans Internals

This module takes you inside a Bean to learn about the structure and organization of data and methods, the two primary parts of a Bean. You learn all about properties, which model the public portion of a Bean's data and are accessible externally through accessor methods.
You take a look at the different types of properties, including simple properties, indexed properties, bound properties, and constrained properties.
Toward the end of the module you work through a practical exercise of creating a property and its associated accessor methods.

Module Learning Objectives

After completing this module, you will have the knowledge and skills necessary to:
  1. Design and code properties for your own Beans
  2. Define accessor methods used to access properties
  3. Understand when and why to use indexed, bound, and constrained properties
The two primary components of a JavaBean are indeed:
  1. Data: Represented by private fields that encapsulate the object's state. These fields typically store the bean's properties, which define its characteristics and behavior.
  2. Methods: Public methods that provide access to and manipulate the object's data. These methods allow other parts of your program to interact with the bean, get or set its properties, and trigger its actions.

By following these conventions, JavaBeans become reusable and modular components that can be easily integrated into different applications. This makes them a valuable tool for developers who want to build clean, maintainable, and flexible software.


Ad Developing Java Beans

JavaBeans Architecture

The JavaBeans architecture is supposed to scale well from small to large; simple beans can be used to build larger beans. A small bean may consist of a single class; a large bean may have many. Beans can also work together through their container to provide services to other beans. Simple beans are little more than ordinary Java objects.
  1. In fact, any Java class that has a default (empty) constructor could be considered a bean.
  2. A bean should also be serializable, although the JavaBeans specification does not strictly require that.
These two criteria ensure that we can create an instance of the bean dynamically and that we can later save the bean as part of a group or composition of beans. There are no other requirements. Beans are not required to inherit from a base bean class, and they do not have to implement any special interface. A useful bean should send and receive events and expose its properties to the world. To do so, it follows the appropriate design patterns for naming the relevant methods so that these features can be automatically discovered. Most nontrivial beans intended for use in a visual application builder IDE also provide information about themselves in the form of a BeanInfo class. A BeanInfo class implements the BeanInfo interface, which holds methods that describe a bean's features in more detail, along with extra packaging, such as icons for display to the user. Normally, this "bean info" is supplied by a separate class that is named for and supplied with the bean.
In the next lesson, the structural makeup of a Bean will be discused.

SEMrush Software