When writing programs via a text editor, a JavaBean is no different than any other Java component.

However, if you write code using a Bean enabled Java IDE, there is a big difference.

What makes a component a JavaBean? Simple.

How to Create a JavaBean

This code will compile the source and place the .class file in the specified directory.

Bean Properties

As stated previously, the development environment handles the bean functions. The IDE checks the manifest of the available JAR files in order to display the beans on the palette. Once a bean is placed on the form, the IDE searches the .class file for methods of the form It then places propName in the property list, and expects the properties to be of the specified type. (Notice the that the "p" is capitalized in the method names, and lower case in the property list.)

If a property is of type Boolean (True/False), then the methods should be IsPropName and SetPropName.

Comparison with Delphi

This is similar to Delphi's published properties. The main differences are

Additional Capabilities

Via the IDE, each bean property can be associated with the property of another bean. Thus, you can associate the position of a slide bar with the value in a text field without writing any additional code. (Well, the bean actually needs additional code to handle this, but that is added when the bean is designed. When the bean is used, no additional code is added.)

While pretty cool, this is really a minor function of beans.


JAR - Java Archive
Conceptually similar to a zip file. It can contain any number of files, including .class files (compiled java files), images (jpeg), text files, and so forth.

A text file used to describe the contents of a JAR file. It specifically identifies which .class files are beans. It may specify which .class file contains a main subroutine.

IDE - Integrated Design Environment
Basically a source editor with additional capabilities, such as an integrated compiler which also shows you where the errors are.

Author: Robert Clemenzi -
URL: http:// / user / clemenzi / technical / Languages / Java / JavaBeans.html