Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introducing JavaBeans Identify the features of a JavaBean Create and add a bean to an application Manipulate bean properties using accessor and mutator.

Similar presentations


Presentation on theme: "Introducing JavaBeans Identify the features of a JavaBean Create and add a bean to an application Manipulate bean properties using accessor and mutator."— Presentation transcript:

1 Introducing JavaBeans Identify the features of a JavaBean Create and add a bean to an application Manipulate bean properties using accessor and mutator methods

2 Introducing JavaBeans Getting Started Object Is a runtime instance of a class Software components: Are reusable objects Pluggable into any software application from any vendor Examples - Spell-check utility, find and replace utility JavaBeans Are reusable and self-contained software components created using Java

3 Introducing JavaBeans Getting Started (Contd.) JavaBeans – Development Phases: Construction phase Involves creation of a JavaBean and its user interface Build phase Involves placing the JavaBean into the target container Execution Phase Involves execution of the the container application in which the JavaBean is placed

4 Introducing JavaBeans Getting Started (Contd.) 3 Construction Phase involves creation of the following: ä.class files ä.mft file ä.jar file *Elements of a JavaBean 3 Properties ä Are the private member data contained in a JavaBean

5 Introducing JavaBeans Getting Started (Contd.) 3Methods ä Are the public member functions used to: ä Manipulate bean properties ä Expose bean functionality 3Events ä Are used to communicate changes in bean property values or changes in its state to other beans

6 Introducing JavaBeans Getting Started (Contd.) *The JavaBean Component Specification 3Customization ä Is the ability of a JavaBean to allow its properties to be changed 3Persistence ä Is the ability of a bean to save its state 3Communication ä Is the ability of a bean to inform changes in its attributes to other beans and to the container application

7 Introducing JavaBeans Getting Started (Contd.) Introspection Is the ability of a bean to be queried by external applications Types of JavaBeans Bean typeDescription Control beansAre used to create graphical user interface components Container beansAre used to hold other Java beans Invisible Runtime beans Are used to create components that perform a specific task in the background

8 Introducing JavaBeans Building an Application Using Existing Beans To identify the software to be used to build and test the components and familiarize yourself with the software by creating an application similar to the one shown below:

9 Introducing JavaBeans Task List Identify the software to be used to create the application Identify the beans to be added to the BeanBox window Add the beans to the BeanBox window Associate events with the beans Save and execute the application

10 Introducing JavaBeans Task 1: Identify the software to be used to create the application Beans Development Kit Is used as a tool to: Build bean based applications Test bean functionality Contains several example beans To start BDK Execute the run.bat file from the command prompt.

11 Introducing JavaBeans Task 1: Identify the software to be used to create the application (Contd.) The following windows appear on starting BDK: Window nameDescription ToolBoxContains a list of sample beans supplied with BDK BeanBoxActs as a form or a container for the beans that make up an application PropertiesDisplays the properties of the bean currently selected in the BeanBox window Method TracerKeeps track of method invocations across beans

12 Introducing JavaBeans Task 1: Identify the software to be used to create the application (Contd.) Result: BDK will be used to test the beans

13 Introducing JavaBeans Task 2: Identify the beans to be added to the BeanBox Result: The application uses two beans that are supplied with the BDK software Juggler bean Two instances of the OurButton bean

14 Introducing JavaBeans Task 3: Add the beans to the BeanBox window Task 4: Associate events with the beans Task 5: Save and execute the application

15 Introducing JavaBeans ä The Juggler bean is an example of a ____ type of bean. ä Which window of BDK is used to change the background color of a bean? ä Which window of BDK is used to build a bean application?

16 Introducing JavaBeans Creating Beans and Building Applications A customer can access his account only after entering the pin number. You need to construct and test the component for the ATM application. The specifications for the component are given below: 3It should display the logo of the bank as an animation. You might plug in the login component into the ATM application of any bank. So, the logo should be modifiable according to the ATM application of a particular bank into which the component is plugged in 3It should accept the pin number of a customer

17 Introducing JavaBeans Creating Beans and Building Applications (Contd.) 3It should contain a method that checks if the pin number entered by a customer is present in the Earnest Bank database. This feature is specific to the Earnest Bank ATM application After you create the login component, build a sample application and test the functionality of the component. The user interface of the sample login application should look similar to the one shown:

18 Introducing JavaBeans Creating Beans and Building Applications (Contd.) The user interface of the sample login application should look similar to the one shown:

19 Introducing JavaBeans Task List *Identify the controls to be used *Identify the properties to be exposed by the bean *Identify the methods to be supported by the bean *Create the User Interface of the bean *Add code to expose the bean properties *Code the methods to be supported by the bean *Save and compile the program *Create the.mft file *Create the.jar file

20 Introducing JavaBeans Task List *Load the bean into BDK *Build an application using the bean *Execute the application and verify the functionality of the bean

21 Introducing JavaBeans Task 1: Identify the controls to be used Result: 3The controls to be used are: ä A label and text field control for accepting the pin number ä A label control for displaying the bank logo

22 Introducing JavaBeans Task 2: Identify the properties to be exposed by the bean Result: 3The logo property should be exposed

23 Introducing JavaBeans Task 3: Identify the methods to be supported by the bean Result: 3A method named validatePinNo()needs to be coded in the component Task 4: Create the User Interface of the bean

24 Introducing JavaBeans Task 5: Add code to expose the bean properties *Properties of a Bean: 3Are the characteristics of a bean 3Are used to change the appearance and behavior of a bean 3Example: ä Properties that have to be exposed by a spell check utility can be coded as: private String language; private String dictionaryPath;

25 Introducing JavaBeans Task 5: Add code to expose the bean properties (Contd.) *Accessor and Mutator Methods 3Are used to make the properties of a bean available to the outside world 3Are used to ensure the integrity of bean data *get method ä Allows the current value of a property to be read *set method ä Allows the current value of the property to be changed

26 Introducing JavaBeans Task 6: Code the methods to be supported by the bean Task 7: Save and compile the program

27 Introducing JavaBeans Task 8: Create the.mft file *The Manifest file: 3Is used by the target application to recognize a JavaBean 3Is saved with a.mft extension 3Contains a list of all class files that make up a JavaBean

28 Introducing JavaBeans Task 9: Create the.jar file *The JAR file: 3Is similar to a zip file 3Is used to package a JavaBean for distribution 3Contains the manifest file and all other files such as the class files and picture files of the bean 3Has a.jar extension

29 Introducing JavaBeans Task 10: Load the bean into BDK Task 11: Build an application using the bean Task 12: Execute the application and verify the functionality of the bean

30 Introducing JavaBeans Creating Beans and Building Applications(try out) A component needs to be created that accepts the login id and password of a customer. The component should wait for 30 seconds before the user enters the login information. The code for the component is given below. You need to modify the code to do the following: If the user does not login for the specified time, a login time out message should be displayed The time out message to be displayed will be specified during the build phase The component should be pluggable into the ATM application of any bank

31 Introducing JavaBeans An object is a run-time instance of a class. A component is a reusable object that can be embedded into any software application from any vendor. The SpellCheck utility is an example of a component Beans created using Java takes advantage of all the security and platform independent features of Java A JavaBean exists in one of the following three phases: the construction phase, the build phase, and the execution phase

32 Introducing JavaBeans As per the JavaBean Component Specification, a simple Java object must support the following five features for it to become a JavaBean: 3Properties 3Customization 3Persistence 3Communication 3Introspection

33 Introducing JavaBeans *You can create three types of beans: 3Control beans 3Container beans 3Invisible run-time beans *A wide variety of application development environments such as Forte For Java, IBM Visual Age, Kawa, Beans Development Kit (BDK) and Symantec Visual Cafe are available in the market that support the creation, building, and testing of Java beans *BDK can be used as build tool to build bean applications or as a testing tool to test the beans for their intended functionality

34 Introducing JavaBeans  Execute the run.bat file from the command prompt to start BDK  On starting BDK, the ToolBox palette, the BeanBox window, and the Properties window are displayed  BDK consists of several re-usable sample beans such as the Juggler bean and the OurButton bean *Properties are the characteristics of a bean and are similar to the data members of a class. By changing the properties, you can change the appearance and behavior of a bean *The get and set accessor methods are used to expose the bean properties to external applications

35 Introducing JavaBeans  The manifest file contains information about a bean such as the name of the bean and the files present in the. jar file of the bean  JavaBeans are packaged and distributed as. jar files


Download ppt "Introducing JavaBeans Identify the features of a JavaBean Create and add a bean to an application Manipulate bean properties using accessor and mutator."

Similar presentations


Ads by Google