Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

A walking tour of JavaBeans

What JavaBeans is, how it works, and why you want to use it

  • Print
  • Feedback
The Java Development Kit (JDK) 1.1 hit the streets in February, bringing with it a new API called JavaBeans. JavaBeans is the software component architecture for the Java language. Why should Java developers be interested in this component technology? In this article, we'll start with a brief explanation of component technology and why it's useful in system architecture. Then we'll look at JavaBeans to see what features the Beans API provides. We'll finish with a preview of a regular series of articles that will explain how the new core APIs work with and within Beans, and how to use the JavaBeans API to create your own software components.

What is software component technology?

Software components are to software what integrated circuits (ICs) are to electronics: "black boxes" that encapsulate functionality and provide services based on a specification. Software reusability has long been a holy grail of software engineering and a major goal of object-oriented programming. Software components are designed to be reusable, even interchangeable.

In the "old days," people experimenting with radio had to spend a lot of time building chassis, winding inductors, and wiring together smaller components to create amplifiers, filters, and oscillators. Today, these components come packaged as integrated circuits with inputs, outputs, and specifications that tell how each component works. The specification is a sort of contract between the creator of the component and its user, explaining how the component will behave in various circumstances. Combine these components correctly, and, voila!, you have a radio. (Or, voila!, a heart rate monitor or microwave oven. You get the picture.) If the component doesn't perform to its specification, it is considered defective and can be replaced.

Software components give programmers the same benefits that the above components give to people building radios. They provide specific functionality that can be reused in different places. Any software component conforming to the same specification can be replaced with another that performs the same function -- without breaking the system. Programmers can then connect software components together to create different applications, just as an electrical engineer wires together components to create a new radio, heart rate monitor, or microwave oven.

What is a software component?

Software components hide implementation, conform to interfaces, and encapsulate data, just like classes do in object-oriented languages. So how do components differ from classes? The answer: Almost all software components are also classes. What makes them components is their conformance to a software component specification. The JavaBeans Specification is the document that describes what a Java class must do to be considered a "Bean." Programmers (and, as importantly, integrated development environments [IDEs]) can depend on any class that advertises itself as a Bean to conform to the rules set out in the specification. If it doesn't conform, the contract has been broken and the Bean is defective.

  • Print
  • Feedback

Resources
  • An excellent comparison of JavaBeans and ActiveX can be found in Merlin Hughes' JavaWorld cover story, "JavaBeans and ActiveX go head to head"
    http://www.javaworld.com/javaworld/jw-03-1997/jw-03-avb-tech.html
  • Sun Microsystems maintains a Web site for JavaBeans. On this site, you can download the latest BDK (Beans Developer's Kit), read the JavaBeans Specification, surf through an online tutorial, and find out about the latest information on Beans. http://java.sun.com/beans
  • The JavaBeans Advisor, an occasional electronic newsletter containing Beans news and developer tips, is archived at
    http://splash.javasoft.com/beans/Advisor.html
  • The JavaBeans FAQ maintained by Sun is at
    http://splash.javasoft.com/beans/FAQ.html
  • Finally, omphaloskepsis is a form of introspective meditation involving intense contemplation of the navel. Check out the Word A Day Web site, and fill your daily speech with obscure references! http://www.wordsmith.org/awad/index.html