What’s a Bean?
What exactly is or are JavaBeans? JavaBeans (the architecture) defines a set of rules; Java beans are ordinary Java objects that play by these rules. That is, Java beans are Java objects that conform to the JavaBeans API and design patterns. By doing so, they can be recognized and manipulated by tools (especially visual application builder environments) as well as by hand coding. Beans live and work in the Java runtime system, as do all Java objects. They communicate with their neighbors using events and other normal method invocations.
For examples of Java beans, we need look no further than the
javax.swing packages. All the familiar
components, such as JButton, JTextArea, and JScrollpane, follow the JavaBeans design
patterns and are beans. Much of what you learned in Chapter 16 about Swing components prepared you for
understanding beans. Although most of the Swing components aren’t very
useful in isolation, in general, beans can also be large and complex
application components, such as spreadsheets or document editors. We’ll
talk more about exactly what makes a bean a bean in a moment. For now, we
want to give you a better sense of how they are used.
One of the goals of JavaBeans is to allow components to be manipulated visually within a graphical application builder. Beans can be chosen from a palette of tools and manipulated graphically by an application designer. The Swing components we mentioned earlier are obvious candidates for this kind of usage. But Java beans ...