java be an intro xi

Upload: divyesh-shukla

Post on 07-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Java Be an Intro XI

    1/20

    Java BeansJava Beans

  • 8/6/2019 Java Be an Intro XI

    2/20

    ContentContent

    What is a Java Bean?What is a Java Bean?

    BDKBDK What makes Bean possible?What makes Bean possible?

    Support for Java BeanSupport for Java Bean

    ReferencesReferences

  • 8/6/2019 Java Be an Intro XI

    3/20

    What are Java Beans?What are Java Beans?

    Software ComponentSoftware Component

    Specified interfaces.Specified interfaces.

    Independent deployment.Independent deployment.

    AnalogyAnalogy

    Electronic components.Electronic components.

    Automotive components.Automotive components.

  • 8/6/2019 Java Be an Intro XI

    4/20

    What are Java Beans? ...What are Java Beans? ...

    Definition:Definition:

    A Java bean is a reusable software component that canA Java bean is a reusable software component that canbe visuallymanipulated in builder tools.be visuallymanipulated in builder tools.

    Java Bean TutorialsJava Bean Tutorials

    TheThe JavaBeansJavaBeans SpecsSpecs areare availableavailable f orfordownloadingdownloading atat

    httphttp:://java//java..sunsun..com/products/javabeans/docs/com/products/javabeans/docs/

  • 8/6/2019 Java Be an Intro XI

    5/20

    What is JavaBeans?What is JavaBeans? A Java Bean is a reusable softwareA Java Bean is a reusable software

    component that can be manipulated visuallycomponent that can be manipulated visuallyin a builder toolin a builder tool JavaBeans is aJavaBeans is a portable, platformportable, platform--independent componentindependent component

    modelmodel written in the Java programming language, developedwritten in the Java programming language, developedin collaboration with industry leaders.in collaboration with industry leaders.

    It enables developers toIt enables developers towritewrite reusable componentsreusable components onceonceandand runrun themthem anywhereanywhere ---- benefiting from the platformbenefiting from the platform--independent powerof Java technology.independent powerof Java technology.

    The goal of JavaBeans is to create a system wherebyThe goal of JavaBeans is to create a system wherebyapplication developers can take a setof beans from a stockapplication developers can take a setof beans from a stocklibrary and wire them together to make a full applicationlibrary and wire them together to make a full application

  • 8/6/2019 Java Be an Intro XI

    6/20

    Software ComponentsSoftware Components

    A software component is a unit of

    composition with contractually specified

    interfaces and explicit context dependenciesonly. A software component can be deployed

    independently and is subject to composition

    by third parties.

    Szyperski ECOOP96

  • 8/6/2019 Java Be an Intro XI

    7/20

    Composition not InheritanceComposition not InheritanceIn OO languages, new objects are created

    from old using the inheritance mechanism.

    Pluggable components are connected

    together by composition rather than

    inheritance.

    Most of the flexibility of inheritance can

    be gained from various compositionaltactics.

  • 8/6/2019 Java Be an Intro XI

    8/20

    Features of JavaBeansFeatures of JavaBeans

    Support forSupport forintrospectionintrospection

    so that a builder tool can analyze how a bean worksso that a builder tool can analyze how a bean works

    Support forSupport forcustomizationcustomization

    so that when using an application builder a user can customizeso that when using an application builder a user can customize

    the appearance and behaviorof a beanthe appearance and behaviorof a bean Support forSupport foreventsevents

    as a simple communication metaphor than can be used toas a simple communication metaphor than can be used toconnect up beansconnect up beans

    Support forSupport forpropertiesproperties

    both for customization and for programmatic useboth for customization and for programmatic use

    Support forSupport forpersistencepersistence

    so that a bean can be customized in an application builder andso that a bean can be customized in an application builder andthen have its customized state saved away and reloaded laterthen have its customized state saved away and reloaded later

  • 8/6/2019 Java Be an Intro XI

    9/20

    Persistent StoragePersistent Storage

    Purpose:Purpose:

    To use existing data formats and plug into OLE or OpenDocTo use existing data formats and plug into OLE or OpenDocdocuments (e.g., Excel doc inside a Word doc)documents (e.g., Excel doc inside a Word doc)

    To be trivial for the common case of a tiny Bean (by saving itsTo be trivial for the common case of a tiny Bean (by saving itsinternal state)internal state)

    SolutionsSolutions

    ExternalizationExternalization: provides a Bean with full control over the: provides a Bean with full control over theresulting data layout.resulting data layout.

    SerializationSerialization: provides an automatic wayof storingout and: provides an automatic wayof storingout andrestoring the internal state of a collection of Java objectsrestoring the internal state of a collection of Java objects

    All bean must support either Serialization or ExternalizationAll bean must support either Serialization or Externalization

  • 8/6/2019 Java Be an Intro XI

    10/20

  • 8/6/2019 Java Be an Intro XI

    11/20

    What makes this possible?What makes this possible?

    PropertiesProperties

    EventsEvents

    PersistencePersistence

    IntrospectionIntrospection

    CustomizationCustomization

  • 8/6/2019 Java Be an Intro XI

    12/20

    PropertiesProperties

    Attributes.Attributes.

    Can be read/write, readCan be read/write, read--onlyor writeonlyor write--only.only.

    Several types of properties:Several types of properties:

    SimpleSimple

    IndexedIndexed

    BoundBound

    ConstrainedConstrained

  • 8/6/2019 Java Be an Intro XI

    13/20

    EventsEvents

    Message sent from one object to another.Message sent from one object to another.

    SenderSender firesfires event, recipient (listener)event, recipient (listener) handleshandlesthe eventthe event

    There may be many listeners.There may be many listeners.

    Event

    source

    Event

    listenerFire event

    Event

    Object

    Register listener

  • 8/6/2019 Java Be an Intro XI

    14/20

    Event

    source

    Event

    Adapter

    Fire eventEvent

    Object

    Register event listener

    EventListener

    Forward eventEvent

    ObjectProvide

    interface

  • 8/6/2019 Java Be an Intro XI

    15/20

    PersistencePersistence

    Allows the graphical builder torecall theAllows the graphical builder torecall thestate of a bean.state of a bean.

    public class Button implements java.io.Serializable { ... }public class Button implements java.io.Serializable { ... }

    Selected property fields can bypass theSelected property fields can bypass the

    serialization using keywordsserialization using keywords transienttransientororstaticstatic..

  • 8/6/2019 Java Be an Intro XI

    16/20

    IntrospectionIntrospection

    A mechanism that allows the builder toolA mechanism that allows the builder toolto analyze a bean.to analyze a bean.

    Two ways to analyze a bean:Two ways to analyze a bean:

    lowlow--level reflection APIs.level reflection APIs.

    vendor provided explicit informationvendor provided explicit information

    (Customization).(Customization).

    Application builder will provide defaultApplication builder will provide defaultBeanInfo classBeanInfo class BeanInfo.BeanInfo.

  • 8/6/2019 Java Be an Intro XI

    17/20

    ConclusionConclusion

    Easy to use.Easy to use.

    Difficult to build.Difficult to build.

    Like all OO design, needs careful planning.Like all OO design, needs careful planning.

    Similar to the String library in C++.Similar to the String library in C++.

    Wide selection of JavaBeans in the future?Wide selection of JavaBeans in the future?

  • 8/6/2019 Java Be an Intro XI

    18/20

    SupportSupport

    BDKBDK -- SunSun

    NetBeansNetBeans www.netbeans.orgwww.netbeans.org

    JbuilderJbuilder -- InpriseInprise

    Super MojoSuper Mojo -- PenumbraSoftwarePenumbraSoftware

    Visual Age for Java

    Visual Age for Java -- IBMIBM

    Visual CafeVisual Cafe -- Symantec CorporationSymantec Corporation

    JDeveloper SuiteJDeveloper Suite -- OracleOracle

  • 8/6/2019 Java Be an Intro XI

    19/20

    ReferencesReferences

    http://java.sun.com/products/javabeans/http://java.sun.com/products/javabeans/

    Java Developer Connection TutorialsJava Developer Connection Tutorials

    Java Beans, Part 1 to 4Java Beans, Part 1 to 4

    http://developer.java.sun.com/developer/onlihttp://developer.java.sun.com/developer/onli

    neTraining/neTraining/

  • 8/6/2019 Java Be an Intro XI

    20/20

    References...References...

    Trail: JavaBeansTrail: JavaBeans

    http://java.sun.com/docs/books/tutorial/javabhttp://java.sun.com/docs/books/tutorial/javab

    eans/index.htmleans/index.html

    JavaBeans 1.01 SpecificationJavaBeans 1.01 Specification

    http://java.sun.com/beans/docs/spec.htmlhttp://java.sun.com/beans/docs/spec.html