Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

"Double Shot, Half Decaf, Skinny Latte" -- Customize your Java

How to tailor JavaBeans to fit your application

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Consider the following exchange:

Sally: I'd like the chef salad please with oil and vinegar on the side, and the apple pie a la mode.

Waitress: Chef and apple a la mode.

Sally: But I'd like the pie heated, and I don't want the ice cream on top. I want it on the side, and I'd like strawberry instead of vanilla if you have it. If not, then no ice cream, just whipped cream, but only if it's real. If it's out of the can, then nothing.

Waitress: Not even the pie?

Sally: No, just the pie, but then not heated.



This was Meg Ryan in the role of Sally Albright in the movie When Harry Met Sally.

Sally knows exactly what she wants. As an application designer, so do you. Fortunately, no matter how complex your customization requirements may be, JavaBeans is up to the task. Customization allows an application developer to control the behavior and appearance of a software component. Making a component customizable greatly extends where it can be used. For example, consider a Spreadsheet bean. If such a bean insisted on taking up the whole screen, or clashed with the color scheme of your application, or only displayed its data in hexadecimal, you might not be able to use it -- even if it provided all of the other functionality you needed. A customizable bean has properties (like number of cells, color, and so on) that a developer can view and modify, custom-fitting the bean to the application.

The JavaBeans Specification (hereafter known as "the JavaBeans Spec") includes features that make identifying and modifying component properties extremely easy in simple cases, and provides extensions for more complex situations.

This month, we'll explore the JavaBeans customization interface. You'll learn about component properties, and how to write your beans so that integrated development environments (IDEs) can present those properties to applications developers. We'll discuss bound and constrained properties, which help beans communicate or maintain consistency. We'll also touch on special-case customizers for situations in which you want more control over customization. Finally, we'll start using the BeanBox, Sun's free testbed for JavaBeans. (For more on the BeanBox, see my companion article in this month's JavaWorld: "The BeanBox: SunSoft's JavaBeans test container.")

What is customization?

Software components typically are general-purpose "chunks" of functionality and data, written to be usable in a variety of situations. (For an introduction to JavaBeans, see last month's column in JavaWorld, "A walking tour of JavaBeans.") What's important about customization? A software component can be used in a wider range of applications when the application developer has control over its appearance and behavior. For example, a PushButton class wouldn't be very useful if its text label were always the word "Button," and its associated action were always, say, to reboot your machine (although with some operating systems, this might be one of your most useful tools).

Even a component as simple as a lowly PushButton may have many attributes that a developer might want to control, including:

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • A good starting place for the neophyte beans developer is the JavaBeans tutorial at the following URL. This tutorial is available in PostScript and PDF format. This page also contains links to books about JavaBeans. http://splash.javasoft.com/beans/resources.html
  • The JAR file format is described at http://java.sun.com/products/jdk/1.1/docs/guide/jar/index.html
  • The package java.awt.beans is documented at the following URL. This documentation includes descriptions of the classes discussed in this article. http://java.sun.com/products/jdk/1.1/docs/api/Package-java.beans.html
  • JavaSoft offers a Web site called the Java Developer's Connection. This Web site contains a "short course" on JavaBeans. You'll have to register as a JDC member but, like the JDK, membership in the Java Developer's Connection is free! You can access this course at http://developer.javasoft.com/developer/onlineTraining/newbeans/index.html
  • Here is another online JavaBeans tutorial. It's a work in progress that provides still more examples of how to create JavaBeans. http://java.sun.com/docs/books/tutorial/beans/index.html
  • Any object-oriented programmer should understand and know how to apply design patterns. The Java 1.1 event listener interface is an prime example of a design pattern in action. An excellent place to start is the Patterns home page at http://st-www.cs.uiuc.edu/users/patterns/