Java Bean Definition “A Java Bean is a reusable software component that can be manipulated visually in a builder tool.”

Slides:



Advertisements
Similar presentations
3 Copyright © 2005, Oracle. All rights reserved. Basic Java Syntax and Coding Conventions.
Advertisements

Copyright © 2001 Qusay H. Mahmoud JavaBeans An introduction to component-based development in general Introduction to JavaBeans – Java components – client-side.
Copyright  Oracle Corporation, All rights reserved. 3 JavaBeans: Reusing Application Components.
Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Beans - Events and Properties -
Java Beans & Serialization CS-328 Dick Steflik. Java Beans Java based component technology –originally developed to provide java with a component technology.
JavaBeans introduction Klaus-Peter Heidrich for the University of Karlstad Inst. for Information Technology Dept. of Computer Science.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 15 Advanced Features of Java.
By Dr. Jiang B. Liu 12. The Java Beans. Java Beans n JavaBeans is a portable, platform-independent software component model written in Java. It enables.
JavaBeans A component architecture. What is JavaBeans? NC World (New Computing) Dictionary: JavaBeans n. 1. JavaSoft technology. 2. Component object model.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
JAVA BEANS By Madhuri Kakumanu. What is a Java Bean? “ A Java Bean is a reusable software component that can be visually manipulated in builder tools.”
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Structure of a web application1 Dr Jim Briggs. MVC Structure of a web application2.
M.Sc. Course, Dept. of Informatics and Telecommunications, University of Athens S.Hadjiefthymiades “Web Application Servers” Basics on WAS WAS are necessary.
JAVA BEANS (Unit-V) K.Phani Sirisha.
Introducing JavaBeans Lesson 2A / Slide 1 of 30 JDBC and JavaBeans Pre-assessment Questions 1.Which of the given symbols is used as a placeholder for PreparedStatement.
Introducing JavaBeans Identify the features of a JavaBean Create and add a bean to an application Manipulate bean properties using accessor and mutator.
Java Beans.  Java offers software component development through java Beans  Java Beans are based on a software component model for java.  The model.
Java Beans Component Technology Integrated, Visual Development Environments Reusable Platform-Independent Modular.
Component-Based Software Engineering Introduction to Java Beans Paul Krause and Sotiris Moschoyiannis.
Java Beans.
Chapter 10 Introduction to Components. Process Phases Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFramework Detailed.
SWE 316: Software Design and Architecture Objectives Lecture # 19 Java Beans SWE 316: Software Design and Architecture  Understand  what JavaBeans (“Beans”)
Last update October 18, 2004 Advanced Programming 2004 Java Beans.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Introduction to Java Beans by Anders Børjesson. Introduction to JavaBeans2 JavaBeans components JavaBeans are the components in the Java environment Many.
JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.
TM Introduction to JavaBeans™ Dimitrios Psarros Questra Consulting (716) x225.
CIS 644 Aug. 25, 1999 tour of Java. First … about the media lectures… we are experimenting with the media format please give feedback.
Comparing JavaBeans and OSGi Towards an Integration of Two Complementary Component Models HUMBERTO CERVANTES JEAN-MARIE FAVRE 09/02.
Java Programming: Advanced Topics 1 JavaBeans Chapter 8.
SWE 316: Software Design and Architecture Objectives Lecture # 18 Introduction to Components SWE 316: Software Design and Architecture To learn:  benefits.
Components Components are specialized self contained Software entities that can be replicated, Customized and inserted into applications. Components come.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Introduction to Java Beans CIS 421 Web-based Java Programming.
Introduction to Java 120 February 2004Sifei HE © 2004 Introduction to Java for CS381, EE4.Web By Sifei HE Department of Computing.
First Bean Compose SimpleBean Demo Simple Bean Discuss Manifest and Jar Add Properties to SimpleBean.
First Bean Compose SimpleBean Demo Simple Bean Discuss Manifest and Jar Add Properties to SimpleBean.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
Java Beans. Definitions A reusable software component that can be manipulated visually in a ‘builder tool’. (from JavaBean Specification) The JavaBeans.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Nick Karstedt. What is the App Inventor for Android?  Simple Development  Web/Java Based  Use of Android software and phone hardware  Portable.
Advanced Java Session 4 New York University School of Continuing and Professional Studies.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Introduction to Java Beans by Anders Børjesson. Introduction to JavaBeans2 JavaBeans components JavaBeans are the components in the Java environment –COM.
JavaBean Component Java bean is a reusable software component that can be manipulated visually in a builder tool Graphic bean and Non-graphic bean Javabean.
Introduction to Java Beans From Anders Børjesson.
Introduction to Software Components: the JavaBeans specs Babak Esfandiari.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Lorenz: Visitor Beans: An Aspect-Oriented Pattern Aspect-oriented pattern: describes a solution to a tangling problem in a particular context.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Java Beans THETOPPERSWAY.COM. Contents What is a Java Bean? Advantages Properties Bean Developers Kit (BDK) What makes Bean possible? Support for Java.
Java Beans - Basics CIS 421 Web-based Java Programming.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Comp1004: Building Better Objects II Encapsulation and Constructors.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Chapter 32 JavaBeans and Bean Events
Structure of a web application
Chapter 36 JavaBeans and Bean Events
Javabeans for dummies.
JavaBeans* ICS 123 Richard N. Taylor & Eric M. Dashofy UC Irvine
Java Beans Sagun Dhakhwa.
JavaBeans and JSP CS-422.
Persistence & Bean Properties
Encapsulation and Constructors
Pre-assessment Questions
Knowledge Byte In this section, you will learn about:
Component-Based Software Engineering
Java Programming: Advanced Topics
Presentation transcript:

Java Bean Definition “A Java Bean is a reusable software component that can be manipulated visually in a builder tool.”

JavaBean Properties –Similar to instance variables. Methods –Same as normal Java methods. –Every property should have accessor (get) and mutator (set) –method. Events –Similar to Swing/AWT event handling.

Features of a Java Bean Support for “introspection” so that a builder tool can analyze how a bean works. Support for “customization” to allow the customisation of the appearance and behaviour of a bean. Support for “events” as a simple communication metaphor than can be used to connect up beans. Support for “properties”, both for customization and for programmatic use. Support for “persistence”, so that a bean can save and restore its customized state.

Why use JavaBeans? Component Granularity Portability Simplicity Uniform, high-quality API that will enable developers to write programs that will perform consistently everywhere.

JavaBeans Vs Class Libraries Beans should be used for software components that can be visually manipulated and customized. Class libraries should be used to provide functionality to programmers, but which doesn't benefit from visual manipulation.

Java Beans Concepts A component is a self-contained reusable software unit Components expose their features (public methods and events) to builder tools A builder tool maintains Beans in a palette or toolbox. You can select a bean from the toolbox, drop it in a form, and modify its appearance and behavior. Also, you can define its interaction with other beans ALL this without a line of code.

Java Bean Characteristics a public class with 0-argument constructor it has properties with access methods it has events it can be customized its state can be saved it can be analyzed by a builder tool

Key Concepts A builder tool discover a bean’s features by a process known as introspection. –Adhering to specific rules (design pattern) when–naming Bean features. –Providing property, method, and event information–with a related Bean Information class. Properties (bean’s appearance and behavior characteristics) can be changed at design-time.

Key Concepts…. Properties can be customized at design-time. Customization can be done: –using property editor –using bean customizers Events are used when beans want to intercommunicate Persistence: for saving and restoring the state Bean’s methods are regular Java methods. Beans will also be running in a multi-threaded environment

Security Issues JavaBeans are subject to the standard Java security model The security model has neither been extended nor relaxed. If a bean runs as an untrusted applet then it will be subject to applet security If a bean runs as a stand-alone application then it will be treated as a normal Java application.

Beans Development Kit (BDK) –To start the BeanBox: run.bat (Windows) run.sh (Unix)

BDK Tool Box contains the beans available Bean Box window is the form where you visually wire beans together. Properties sheet: – displays the properties for the Bean currently selected within the BeanBoxwindow.

MyFirstBean import java.awt.*; import java.io.Serializable; public class FirstBean extends Canvas implementsSerializable { public FirstBean() { setSize(50,30); setBackground(Color.blue); }

First Bean Compile: javac FirstBean.java Create a manifest file: –manifest.txt (jar file metadata) Name: FirstBean.Class Java-Bean: True Create a jar file: –jar cfm FirstBean.jar mani.txt FirstBean.class

Properties Bean’s appearance and behavior –changeable at design time. They are private values Can be accessed through getter and setter methods getter and setter methods must follow some rules -- design patterns (documenting experience)

Design Patterns for properties Property is a subset of a bean’s state –Simple properties Has a single value –Public T getN(); –Public void setN(T arg); –Public boolean isN(); ( isdotted) –Indexed properties Consists of multiple values –Public T getN(index); –Public void setN(int index, T value); –Public T[ ] getN(); –Public void setN(T values[ ]);

Introspection Process of analyzing a bean to determine its capabilities Allows an application builder tool to present information about a software component to the designer –Simple naming conventions –A class that explicitly supplies this information

Properties A builder tool can: –discover a bean’s properties –determine the properties’ read/write attribute –locate an appropriate “property editor” for each type –display the properties (in a sheet) –alter the properties at design-time

Types of Properties Simple Index: multiple-value Properties Bound: provide event notification when value changes Constrained: how proposed changes can be okayed or vetoed by other object

Simple Properties When a builder tool introspect your bean it discovers two methods: –public Color getColor() –public void setColor(Color c) The builder tool knows that a property named “Color” exists -- of type Color. It tries to locate a property editor for that type to display the properties in a sheet.

Simple Properties…. Adding a Color property –Create and initialize a private instance variable private Color color = Color.blue; –Write public getter & setter methods public Color getColor() {return color; } public void setColor(Color c) { color = c;–repaint(); }

Indexed Properties An indexed property is for when a single property can hold an array of values. –The design pattern for these properties is: public void setPropertyName (PropertyType[] list) public void setPropertyName ( PropertyType element, int position) public PropertyType[] getPropertyName () public PropertyType getPropertyName (int position)

For instance, if you were to complete the item indexed property for the AWT List component, it might look something like this: public class ListBean extends List { public String[] getItem () { return getItems (); } public synchronized void setItem (String item[]) { removeAll(); for (int i=0;i<item.length;i++) addItem (item[i]); } public void setItem (String item, int position) { replaceItem (item, position) } The String getItem (int position) routine already exists for List

Bound Properties Provide event notification when value changes In order for the notification to happen, you need to maintain a watch list for PropertyChangeEvents via the PropertyChangeSupport class.PropertyChangeEventPropertyChangeSupport First, you have to create a list of listeners to maintain: private PropertyChangeSupport changes = new PropertyChangeSupport (this); And then, you have to maintain the list: public void addPropertyChangeListener (PropertyChangeListener p) { changes.addPropertyChangeListener (p); } public void removePropertyChangeListener ( PropertyChangeListener p) { changes.removePropertyChangeListener (p); }

Constrained properties Constrained properties are similar to bound properties. In addition to maintaining a list of PropertyChangeListeners, the Bean maintains a list of VetoableChangeListeners.VetoableChangeListener Prior to the Bean changing a property value, it asks the VetoableChangeListeners if its okay. If it isn't, the listener throws a PropertyVetoException, which you declare the set routine to throw. PropertyVetoException

Adding… private VetoableChangeSupport vetoes = new VetoableChangeSupport (this); public void addVetoableChangeListener ( VetoableChangeListener v) { vetoes.addVetoableChangeListener (v); } public void removeVetoableChangeListener ( VetoableChangeListener v) { vetoes.removeVetoableChangeListener (v); }