Download 1. JavaBeans as Components

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Java Training: JavaBeans as Components
1.1
1. JavaBeans as
Components
JavaBeans as Reusable Components
The Java Component Model
Uses of JavaBeans
SKILLBUILDERS
© 2001-2006 SkillBuilders, Inc.
Java Training
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.2
1.2
What are JavaBeans?
¾ Reusable software components
¾
¾
Written in Java
Implementing the Java Component Model
¾ Beans contain the following features:
¾
¾
¾
¾
¾
Introspection
Customization
Events
Properties
Persistence
Java Training
© 2001-2006 SkillBuilders, Inc.
JavaBeans are reusable software components written in Java, and
implementing the Java Component Model.
JavaBeans are portable, platform-independent, reusable software
components written in Java. JavaBeans enables developers to write
reusable components once and run them anywhere, thereby benefiting from
the platform-independent power of Java.
Since any Java object is potentially a reusable software component. and
any Java object is portable - because Java itself is portable, what's so
special about JavaBeans?
JavaBeans implement the Java Component Model - defined in the
JavaBeans Specification - which gives them a variety of benefits, exposing
their features, representing features for use, and making JavaBeans
especially reusable.
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.3
Beans contain the following features:
¾Introspection - enables a builder tool to analyze how a bean works
¾Customization - enables a developer to us an application builder tool to
customize the appearance and behavior of a Bean
¾Events - enable Beans to communicate and connect together
¾Properties - enable developers to customize and program with Beans
¾Persistence - enables developers to customize Beans in an application builder
tool, then retrieve those Beans with the customized features intact for future use.
JavaBeans can be manipulated visually or programmatically by other software,
including builder tools and code generators. Beans can be combined to create
traditional applications, or applets.
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.4
1.4
Why Use JavaBeans?
¾ JavaBeans can make application development faster,
easier, and possibly less costly.
¾ JavaBeans are useful if code is:
¾
¾
Highly reusable
Creating a generic component that can be used in several
applications or many times within a single application
¾ Two important reasons for using Beans are:
¾
¾
Creating customizable, reusable components that enable
you to cut down on development time.
Use existing Beans available on the internet and through
other sources to speed your development process.
Java Training
© 2001-2006 SkillBuilders, Inc.
If your code is highly reusable, or if you are creating a generic component
that can be used in several applications or many times within a single
application, Java Beans can make your application development faster,
easier, and possibly less costly.
Two important reasons for using Beans are:
1. Creating customizable, reusable components that enable you to cut down
on development time.
Take for example a simple button. Creating a Java Bean that implements a
button provides you with a prototype for buttons in your application. You can
customize the Bean to meet the requirements for any type of button you
need in your application. Rather than coding several kinds of buttons, sizes
of buttons, colors of buttons, you simply reuse your Java Bean, customizing
it as needed.
2. Use existing Beans available on the internet and through other sources to
speed your development process.
Since many functionalities are already implemented by Java Beans, you can
speed your development process by simply obtaining the Beans you're
interested in, customizing them to meet your specific needs, and then using
them in your application.
Continued...
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.5
There are many sources on the internet for downloading Java Beans. To find the
Beans you need, check out:
http://java.sun.com/beans/directory.html.
This page has a searchable list of Beans from third-party vendors for application
areas including authoring tools, charts, graphs, Database, GUI Elements, and much
more.
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.6
1.6
Who Needs JavaBeans?
¾ Developers interested in “Write Once, Run
Anywhere”.
¾ JavaBeans provide a high level of portability.
¾
¾
They run on any platform
They can connect via bridges into other
component models
Java Training
© 2001-2006 SkillBuilders, Inc.
Developers who are interested in programming by the "Write Once, Run
Anywhere" philosophy will want to use Java Beans to extend the concept of
reusable component development beyond one platfrom and one
architecture. Java Beans enables developers to write reusable components
that run on every platform and architecture in the industry.
Because Java Beans run on any platform and can connect via bridges into
other component models, they provide a high level of portability. This
portablility can help ensure that Bean developers do not lose customers
because of interoperability issues. Bean developers can also sell their
Beans, since there is a growing need for Beans as the market broadens.
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.7
1.7
Java Component Model
¾ The component model defined in the
JavaBeans Specification:
¾
An official document released by Sun
Microsystems
¾ Defines standards for:
¾
¾
¾
Exposing features of a JavaBean
Using exposed features of a JavaBean
Exposure of JavaBean features is based on
design patterns
Java Training
© 2001-2006 SkillBuilders, Inc.
An unofficial phrase for the component model defined in the JavaBeans
Specification, an official document released by Sun Microsystems.
The Java Beans Specification
The Java Component Model is defined in the JavaBeans Specification, an
official document released by Sun Microsystems. The JavaBeans
Specification defines standards for exposing features and for using exposed
features of a JavaBean. These together make a JavaBean a reusable
software component.
Exposing Features
The standards of the JavaBeans Specification for exposing features of a
JavaBean are design patterns.
Implementing a design pattern exposes a feature. A JavaBean is really any
Java object whose implementation follows design patterns exposing at least
some of its features.
The design patterns exposing features include design patterns for standard
features and for standard information about standard or custom features.
Continued…
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.8
Using Exposed Features
Once features of a JavaBean have been exposed, these exposed features can be
used, making the JavaBean a reusable software component.
The standards of the JavaBeans Specification for using exposed features are really
standard techniques.
On these techniques, exposed features of a JavaBean can be represented as
objects in Java. Methods of these objects can be invoked to use the exposed
features.
Objects representing standard features of a JavaBean are determined using
techniques supported by standard Java packages.
Objects representing standard information about standard or custom features of a
JavaBean are determined using techniques provided in the Beans API. These
objects can also provide descriptive information about exposed features, for
example, to support their use by developers in a builder tool or by users in a
configurable application..
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.9
Java
JavaComponent
ComponentModel...
Model...
1.9
Benefits
¾ The Java Component Model makes
JavaBeans especially reusable.
¾ Benefits include:
¾
¾
¾
¾
¾
Portability
Uniformity
Simplicity
Flexibility
Distributability
Java Training
© 2001-2006 SkillBuilders, Inc.
The Java Component Model defined in the JavaBeans Specification gives a
variety of benefits to JavaBeans, making them especially reusable. These
benefits include:
¾Portability
¾Uniformity
¾Simplicity
¾Flexibility
¾Distributability
Portability
JavaBeans are portable because Java itself is portable.
Uniformity
JavaBeans have uniformity because the JavaBeans Specification defines
standards for exposing features and for using exposed features. These
standards include design patterns exposing features and techniques for
using exposed features.
Continued...
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.10
Any software that follows these standards can expose features of its components or
use exposed features of other components. Developers have to know only the
design patterns and techniques in the JavaBeans Specification, not various
component architectures of many systems or applications. Also, interoperability
between systems and applications written in Java is guaranteed by this uniformity.
Simplicity
JavaBeans are simple because the standards for exposing features and using
exposed features are simple, and because of the simplicity of Java as a
programming language.
Any complexity involved in the implementation of a feature is encapsulated, and is
not expressed through the design pattern used to expose the feature.
Flexibility
JavaBeans are flexible. Since the JavaBeans Specification includes design patterns
for standard features and for standard information about standard or custom
features, any feature can be exposed and used, regardless of whether or not it
follows the design pattern for standard features.
Distributability
JavaBeans are distributable because Java objects are distributable. Further,
JavaBeans can interopertate in distributed contexts, because Java supports
distribution of all language elements, including:
¾Classes
¾Objects
¾Data of primitive types
¾Messages
Classes can be distributed as applets or as classes used by applets. Classes can
also be distributed with distributed objects.
Objects can be distributed explicitly by developers, in streams, using methods of the
ObjectStream class in the package java.io. Messages can be distributed using
Java Remote Method Invocation (RMI). Objects in arguments and return values of
methods are distributed implicitly by RMI.
It is important to note that these capabilities are beyond distribution capabilities in
many other distributed architectures. Other distributed architectures can only
distribute primitive data, and developers have to marshal objects based on
distributed primitive data. Using ObjectStream or RMI, Java can distribute objects
as such, without having to marshal explicitly.
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.11
1.11
Uses of JavaBeans...
¾ JavaBeans can be used to deliver many
different services, and many different
contexts.
¾ These contexts include:
¾
¾
¾
¾
BeanBoxes
Compound Documents
Configurable Applications
Builder Tools
Java Training
© 2001-2006 SkillBuilders, Inc.
JavaBeans can be used to deliver many different services, and many
different contexts. These contexts include:
¾BeanBoxes
¾Compound Documents
¾Configurable Applications
¾Builder Tools
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.12
1.12
...Uses of JavaBeans...
¾ What is a beanbox?
¾
An application that uses exposed features of a
JavaBean via design patterns.
¾ There are several kinds of beanbox:
¾
¾
¾
Compound documents
Configurable applications
Builder tools
Java Training
© 2001-2006 SkillBuilders, Inc.
A beanbox is an application that implements techniques for using exposed
features of a JavaBean, following design patterns in the JavaBeans
Specification.
A JavaBean can be used in any kind of application that is aware of the
design patterns exposing features and implements the techniques for using
exposed features. Such an application is called a beanbox.
By following design patterns in the JavaBeans Specification, beanboxes
acquire all the benefits of the Java Component Model mentioned above.
There are several kinds of beanbox, including:
¾Compound documents
¾Configurable applications
¾Builder tools
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.13
1.13
...Uses of JavaBeans
¾ What is a compound document?
¾
A document including other documents, objects,
or applications.
¾ Compound documents can include
JavaBeans. A compound document can:
¾
¾
Run a JavaBean as a plug-in or a helper
application
Use exposed features of a JavaBean, via the
document application
Java Training
© 2001-2006 SkillBuilders, Inc.
A compound document is a document including other documents, objects, or
applications. Compound documents can include JavaBeans. A compound
document can:
¾run a JavaBean, as a plug-in or a helper application
¾use exposed features of a JavaBean via the document application
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.14
Uses
Usesof
ofJavaBeans...
JavaBeans...
1.14
Compound Documents
¾ Can provide services beyond capabilities of the
document application itself.
¾ These can include:
¾
¾
¾
¾
¾
Formatting Tools
Drawing & Graphing Tools
Web Searching & Navigating Tools
Communications Tools
Media Players
Java Training
¾
¾
¾
¾
¾
Software Installers
Games
Calculators
Database Browsers
Viruses
© 2001-2006 SkillBuilders, Inc.
JavaBeans in a compound document can provide many kinds of service
beyond the capabilities of the document application itself. JavaBeans in a
compound document can include:
¾Formatting Tools
¾Web Searching & Navigating Tools
¾Drawing & Graphing Tools
¾Communications Tools
¾Media Players
¾Software Installers
¾Games
¾Calculators
¾Database Browsers
¾Viruses
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.15
Uses
Usesof
ofJavaBeans...
JavaBeans...
1.15
Configurable Applications
¾ JavaBeans can also be used in configurable
applications such as:
¾
¾
Self-configuring
User-configurable
¾ The kinds of configuration supported by a
configurable application using JavaBeans
include:
¾
¾
¾
JavaBean component implementations
Feature options provided by a JavaBean
Assemblies of many JavaBeans together (e.g. as
event listeners or handlers)
Java Training
© 2001-2006 SkillBuilders, Inc.
JavaBeans can also be used in configurable applications such as:
¾Self-configuring
¾User-configurable
The kinds of configuration supported by a configurable application using
JavaBeans include:
¾JavaBean component implementations
¾feature options provided by a JavaBean
¾assemblies of many JavaBeans together (e.g. as event listeners or
handlers)
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.16
Uses
Usesof
ofJavaBeans...
JavaBeans...
1.16
Builder Tools
¾ An important use is in builder tools, e.g.
¾
¾
Programming tools
Integrated development environments
¾ A founding objective of the JavaBeans Specification.
¾ Exposing JavaBean features allows a builder tool to
generate code for:
¾
¾
¾
Subclassing or initializing a JavaBean
Extending features
Choosing feature options
Java Training
© 2001-2006 SkillBuilders, Inc.
An important use of JavaBeans is in builder tools, ranging from programming
tools to integrated development environments. The use of JavaBeans in
builder tools is a founding objective of the JavaBeans Specification because
builder tools simplify and speed up the development process.
Exposing the features of a JavaBean allows a builder tool to generate code
for subclassing or initializing a JavaBean, extending features or choosing
feature options. It also allows the builder tool to support assembling many
JavaBeans together in an application.
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
1.17
1.17
Where We've Been
¾ JavaBeans are Java components.
¾
¾
Java classes packaged as components
They adhere to the Java Component model.
¾ Beans “expose” features.
¾
Properties, events, methods.
¾ JavaBeans can be used in:
¾
¾
¾
Beanboxes
Compound documents
Builder tools
Java Training
© 2001-2006 SkillBuilders, Inc.
© 2001-2006 SkillBuilders, Inc.
V 2.0
Java Training: JavaBeans as Components
© 2001-2006 SkillBuilders, Inc.
1.18
V 2.0