(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

Summary
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)

rule_ltblue.gif


Page 1 of 3

Advertisement
?SIT=jw-BigBox&BA=1

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

Resources

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it Summary-->...
  • Inber
  • Inber
  • 2004年07月09日 14:26
  • 1374

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

A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it Summary-->...
  • Inber
  • Inber
  • 2004年07月09日 14:22
  • 1305

POJO和JavaBeans的区别

POJO你当成JavaBeans的一种,一个特例:简单的实体类。 就是一个数据载体。 区别一: POJO就是一个数据载体 一般是没有业务处理能力。 区别二: POJO是new创建,由GC回收...
  • lilie008
  • lilie008
  • 2015年03月12日 18:19
  • 413

ZOJ3498 Javabeans(找规律)

Javabeans Time Limit: 2 Seconds      Memory Limit: 65536 KB Javabeans are delicious. Javaman l...
  • u011697060
  • u011697060
  • 2014年03月08日 19:49
  • 743

[基础规范]JavaBeans规范

维基百科中javaBeans的解释。
  • sushengmiyan
  • sushengmiyan
  • 2014年10月21日 15:34
  • 3236

OCP-1Z0-053-V12.02-345题

345.What view might you use to try to determine how long a particular backup will take? A. V$SESSION...
  • rlhua
  • rlhua
  • 2013年11月12日 00:25
  • 4264

在JSP页面中使用JavaBeans组件

Bean遵循的规范:1.一定要使用一个包名2.必须有一个默认构造器3.必须实现Serializable或Externalizable接口4.属性通过setter和getter方法访问在JSP页面中生命...
  • mengx
  • mengx
  • 2007年01月21日 14:59
  • 1038

JavaBeans规范

source: https://zh.wikipedia.org/wiki/JavaBeans JavaBeans规范[编辑] 要成为JavaBean类,则必须遵循关于命名、构造器...
  • BalterNotz
  • BalterNotz
  • 2017年01月04日 14:14
  • 384

JavaBeans Activation Framework JAF

JAF(JavaBeans Activation Framework)负责处理MIME编码,JavaMail利用JAF来处理MIME编码的邮件附件 专用的数据处理框架,它用于封装数据,并为应用程序提...
  • liuxianbing119
  • liuxianbing119
  • 2013年02月27日 14:44
  • 948

2014ACM集训13级PK赛2-Javabeans

Description Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n box...
  • u012943138
  • u012943138
  • 2014年03月09日 22:09
  • 617
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:(Page 1 of 3 )A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it
举报原因:
原因补充:

(最多只允许输入30个字)