(Page 1 of 3 )A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it

原创 2004年07月09日 14:20:00

A walking tour of JavaBeans

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

The success of rapid application development (RAD) systems like Borland's Delphi and Microsoft's Visual Basic have brought a great deal of attention to the concept of software components. Java has now entered the ring with its own component software specification, JavaBeans. This article -- the first of many JavaBeans columns -- gives a high-level description of JavaBeans, explains why it's useful to developers, and introduces basic JavaBeans concepts. (2,800 words)


Page 1 of 3


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.

To make a class into a component, the programmer must add functionality to the class that has little to do with what makes the class useful. The only requirement to make a class into a Bean is that the class implement the interface java.io.Serializable. The Serializable interface is a new Java 1.1 feature. Serializable classes know how to package themselves into streams of bytes to be transmitted through networks or saved to disk, awaiting later reincarnation.

Interfaces and classes defined in the package java.beans allow a Beans developer to control how the Beans user (a programmer using a particular Bean) may set and get Beans' properties, hook Beans up to communicate with other components, and ask a Beans to describe themselves. (More on all this later.) The component specification outlines how the component must implement these methods.

Given class files that contain Beans, a programmer can create instances of the Beans and connect them together to do useful work. Writing applications with software components instead of writing a traditional program is analogous to wiring together ICs to build a radio instead of using discrete components or rolling your own inductors. What's more, IDEs can analyze Beans, determining their methods and properties, and make wiring Beans together as simple (in some cases, anyway) as drag-and-drop! (If you work through Sun's Beans Tutorial, you'll see just how this works.)

Understanding JavaBeans gives a developer the knowledge necessary to use these new components as they become available. The concepts involved relate to many of the new (post-Java 1.1) features of the Java core. And what's most exciting, it's now possible for a developer to turn existing classes into reusable software components that automatically integrate with Beans-aware IDEs.

Next page >
Page 1 A walking tour of JavaBeans
Page 2 What JavaBeans is, and what it does
Page 3 Event handling




转自:http://wiki.eclipse.org/EGit/User_Guide EGit/User Guide EGit Contents  [h...
  • shanliangliuxing
  • shanliangliuxing
  • 2013年02月04日 16:10
  • 20376


1Z0-051 1. View the Exhibit and examine the structure of the SALES, CUSTOMERS, PRODU...
  • mickeyty
  • mickeyty
  • 2016年05月19日 12:54
  • 3471


控制器进入目录执行pod install: $ pod install Analyzing dependencies [!] The version of CocoaPods used to gene...
  • lichuanlong007
  • lichuanlong007
  • 2016年08月12日 09:36
  • 1992

Microsoft Word Secrets The Why and How of Getting Word to Do What You Want epub

  • 2017年11月29日 18:21
  • 22.69MB
  • 下载

Microsoft Word Secrets The Why and How of Getting Word to Do What You 无水印pdf

  • 2017年11月29日 18:25
  • 56.95MB
  • 下载

What is reflection and how to use it in CSharp ?

What is reflection and how to use it in CSharp ?
  • garcon1986
  • garcon1986
  • 2013年05月22日 03:36
  • 1291

What is Index and how it works in SQL Server?

What is Index and how it works in SQL Server?
  • garcon1986
  • garcon1986
  • 2013年06月27日 21:05
  • 1207

What is Logical Volume Management and How Do You Enable It in Ubuntu?

  • user_friendly
  • user_friendly
  • 2012年03月13日 22:55
  • 621

What is a cronjob and how do I use it?

The cron daemon is a long running process that executes commands at specific dates and times. To sch...
  • karen121l
  • karen121l
  • 2012年02月17日 12:53
  • 164

CoreOS--What is it and why should I care?

  • 2015年01月13日 09:38
  • 984KB
  • 下载
您举报文章:(Page 1 of 3 )A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it