JavaBeans Components. To understand JavaBeans… Proficient experience with the Java language...

33
JavaBeans Components

Transcript of JavaBeans Components. To understand JavaBeans… Proficient experience with the Java language...

Page 1: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

JavaBeans Components

Page 2: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

To understand JavaBeans…

Proficient experience with the Java language required

Knowledge of classes and interfaces

Object-Oriented development and design

Simple Java GUI application programming using AWT

Exposure to Java’s Delegation Event-Handling Model

Page 3: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

JavaBeans Overview

Software Components

JavaBeans Definition

The JavaBeans API

Applying JavaBeans

The Basic Structure of a Bean

Page 4: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Software Components

Discrete, Reusable Software standard

Microsoft’s ActiveX

Distributed Network Environment

Cross-platform

Must be controlled dynamically

Assembled to form applications

Interoperablility standards

Page 5: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

The Component Model

Introspection - Discovery and Registration

Event Handling

Persistence

Visual Presentation - Layout

Application Builder Support

Page 6: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Introspection

Discovery of Component at Run Time

Late Binding

Expose Component Functionality

Component is Isolated, yet Usable

Page 7: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Event Handling

Alert to Internal Change Component Interactivity Listeners

Page 8: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Persistence

Saving State

Storage and Retrieval

Uniform Persistence Mechanism needed

Page 9: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Visual Presentation - Layout

Dynamic Property Control

Physical Layout

Component Interaction and Spatial Requirement

Container/Component Behavior

Page 10: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Application Builder Support

Graphical application builders

Toolboxes and Palettes

Editing Properties

Components must Expose properties and behaviors

Page 11: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

JavaBean Definition

What is a Bean?

The JavaBeans specification states:

A JavaBean is a reusable software component that can be manipulated

visually in a builder tool.

Page 12: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

JavaBeans Benefits and Features

Simple and Compact

Portable

Leverage Strengths of Java Platform

Application Builder Support

Flexible Build-Time Component Editors

Distributed Computing Support

Page 13: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

JavaBeans and Java Java: “Write once, Run Anywhere”

JavaBeans mission statement: “….Reuse Everywhere”

Java provides no component model

JavaBeans specifies framework for reusability and interoperability for components

Java integration requires code-level knowledge

JavaBeans integration requires visual editor

Page 14: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

JavaBeans API

Property Management

Event Handling

Introspection

Persistence

Application Builder Support

Customization

Multithreading

Page 15: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Property Management

Accessor Methods

Indexed Properties

Bound Properties

Constrained Properties

Page 16: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Event Handling

Event Sources

Unicast

Multicast

Event Listeners

Event Objects

Event Adapters

Page 17: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Introspection

Reflection

Design Patterns

Explicit Bean Information

Introspector

Page 18: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Persistence

Storage and Retrieval

Java Object Serialization

Bean controlled persistence

Page 19: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Application Builder Support

Edit and Manipulate Beans

Bundled with Bean Separately

Property Sheets

Property Editors

Customizers

Page 20: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Multithreading

Relies on conventional Java Programming techniques

synchronized keyword

Make sure Beans are thread-safe

Page 21: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Where and How Beans are Used

Web Pages

Liven up static HTML

Interactivity

Applications

Application Builder Tool

Handwritten Code

Bridge Technology

Page 22: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Structure of a JavaBean

Data

Methods

Events

Data Methods

JavaBean

Events

Page 23: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

JavaBeans and the Interface

Data PublicMethods

JavaBean

Interface A

Interface B

Page 24: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

What Constitutes a Bean?

Class must be instantiable

Class must have a default constructor (not officially required by spec, but by most builder tools)

Class must be serializable

Implement Serializable, Externalizable

Class must follow JavaBeans naming conventions (sometimes called design patterns)

Class must use delegation event model

Page 25: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Constructing a Bean

“Must be instantiable” requirement

Not abstract

Not an interface

“Default constructor” requirement

Application builder tools

Persistence

Page 26: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Serialization

Representation as a series of bytes

Storage to non-volatile location

Implement Serializable Interface

Implement Externalizable Interface

Page 27: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

JavaBeans Design Patterns

Naming conventions for automatic Introspection

Example: Property named Height

public int getHeight();

public void setHeight(int h);

Patterns for Event Registration

Page 28: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Delegation Event Model

Introduced in Java 1.1 AWT

Most Java AWT Components are Beans

Simple

Graphical

Reusable

JFC Swing Components are JavaBean compliant

Page 29: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

A Simple Bean

public class FirstBean implements java.io.Serializable{

protected int theValue;

public FirstBean(){}public void setMyValue( int n ){

theValue = n;}public int getMyValue(){

return theValue;}

}

Page 30: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Visual Development Environments

Developer can focus on Business Application

Connect Components Visually

Code-Generation Engine

Stability

Ease of Generation

Knowledge of Underlying Language Helpful

Page 31: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Visual Programming

NetBeans

JBuilder

VisualAge for Java

Eclipse

JDeveloper

Page 32: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Security and JavaBeans

Same security model as Java

Beans are treated like applets

Untrusted applet -> Untrusted Bean

Trusted applet -> Trusted Bean

Program for Untrusted Environments

Page 33: JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.

Summary

JavaBeans satisfies the requirements of a discrete, reusable component model

Visual and Non-Visual JavaBeans can be developed and used in diverse development environments

Java Classes can become JavaBeans by adhering to some minimum standards

Java’s Security Model transfers directly to JavaBeans