SlideShare a Scribd company logo
Java Beans

                                      JAVA BEANS
What are Java Beans?

1. A Java Bean is a software component that is designed to be reusable.
2. It is a java class that has a zero-argument (empty) constructor. So we can either not specify a
   constructor at all, or define a constructor with no arguments.
3. JavaBean class has no public instance variables (fields). Therefore we have to use the accessor
   methods instead of allowing direct access to the private fields.
4. Values are accessed through methods called as getXXX and setXXX. If a class has a method getTitle
   that returns a string, the class is said to have a String property named Title.
5.
6. A bean may perform a simple function, such as checking the spelling of a document, or a complex
   function, such as forecasting the performance of a stock portfolio.
7. A Bean may be visible to an end user, e.g., a button on a graphical user interface. A Bean may also be
   invisible to a user, e.g., software to decode a stream of multimedia information in real time.
8. A Bean may be designed to work autonomously on a user’s workstation or to work in cooperation
   with a set of other distributed components. E.g., software to generate a pie chart from a set of data
   points is an example of a Bean that can execute locally. However, a Bean that provides real-time price
   information from a stock will have to work in cooperation with other distributed software to obtain its
   data.

What are the advantages of using Java beans?

1. A Bean has all the benefits of Java’s “write-once, run-anywhere” paradigm.
2. We can control which properties, events, and methods of a Bean are available to an application
   builder.
3. A Bean may be designed to operate correctly in different locales (environments), and are therefore
   useful in global markets.
4. Auxiliary software can be provided to help a person configure a Bean. This software is only needed
   when the design-time parameters for that component are being set. It does not need to be included in
   the run-time environment.
5. The configuration settings of a Bean can be saved in persistent storage and restored at a later time.
6. A Bean may register to receive events from other objects and can generate events that are sent to other
   objects.

Explain the term “introspection” in the context of Java Beans.

1. Introspection is the process of analyzing a Bean to determine its capabilities. This is an important
   feature of the Java Beans API, because it allows an application builder tool to obtain information
   about a component.
2. There are two ways in which the developer of a Bean can indicate which of its properties, events, and
   methods should be exposed by an application builder tool.
3. In the first method, simple naming conventions are used. These allow the introspection mechanisms to
   infer information about a Bean.
4. In the second way, an additional class is provided that explicitly supplies this information.
5. Design Pattern for Properties:
        a. A design pattern specifies the rules for forming the method signature, return type and even its
            name. Design patterns can provide a useful documentation hint for programmers.
        b. The major design patterns are:
                  i. Property design pattern,
                 ii. Event design pattern, and
                iii. Method design pattern
Prof. Mukesh N. Tekwani                                                                      Page 1 of 8
Java Beans

      c. A property is a named attribute. It specifies the characteristic, behavior and state of the object.
         Properties are functions which can get or set the values of a variable. A property is a subset of
         a Bean’s state. The values assigned to the properties determine the behavior and appearance
         of the component.
      d. Property design patterns are used to identify the publicly accessible properties of a bean.
      e. The setter method is used to set a property and the getter method is used to obtain the
         property.
      f. If a property has only a getter method, JavaBeans assumes that it is a read-only property. If
         both getter and setter methods are defined, JavaBeans assumes it is a read-write property.
      g. There are three types of properties: simple, Boolean and indexed.
      h. Simple Properties:
         A simple property has a single value. The following design pattern is used:
         public T getN()
         public void setN(T arg)
         Here N is the name of the property and T is its type.

             A read/write property has both these methods to access its value. A read-only property has
             only the get method. The write-only property has only the set method.

             Example:
                                                                        }
             private double depth, height, width;
                                                                        public double setDepth(double d)
             public double getDepth()                                   {
             {                                                             depth = d;
                return depth;                                           }

             public double getHeight()                                  public double getWidth()
             {                                                          {
                return height;                                             return width;
             }                                                          }

             public double setHeightdouble h)                           public double setWidth(double w)
             {                                                          {
                height = h;                                                width = w;
             }                                                          }

      i.     Boolean Properties:
             The design pattern is as follows:
             public Boolean isN( );
             public void setN(Boolean a);

      j.     Indexed Properties:
             An indexed property consists of multiple values, i.e,, it is an array of simple properties. It has
             the following design pattern:

             public T getN (int index);
             public void setN (int index, T value);
             public T [ ] getN ();
             public void setN (T values[]);

             Consider an indexed property data. Its getter and setter methods are shown below:
             private double data [ ];

Page 2 of 8                                                                    mukeshtekwani@hotmail.com
Java Beans

            public double getData(int index)                          public double [ ] getData()
            {                                                         {
                return data[index];                                      return data;
            }                                                         }
            public void setData(int index double
            value)                                                    public void setData(double [ ]
            {                                                         values)
                data [index] = value;                                 {
            }                                                         data = new double[values.length];
                                                                      System.arraycopy(values, 0, data, 0,
                                                                      values.length);
                                                                      }


6. Design Pattern for Events:
   When a Bean’s internal state changes, it is often necessary to inform the other object of the change.
   Beans can do this by communicating events with other objects.

    Beans send event notifications to event listeners that have registered themselves with a bean. Beans
    use the delegation event model. An event is generated by the bean and sent to other objects.

            public void addTListener(TListener eventListener);
            public void removeTListener(TListener eventListener);

    These methods are used to add or remove a listener for the specified event.

    For example, to add support for event listener that implements the ActionListener interface, we write:

            public void addActionListener(ActionListener al);
            public void removeActionListener(ActionListener al);

    TheActionListener interface is used to receive actions like mouse clicks.

7. Constrained Bean Property:
   A Bean property is constrained when any change to that property can be prevented. The Bean can
   itself prevent a property change.

    The 3 parts of a constrained property implementation are:
       • A source bean containing constrained properties.
       • Listener object that can accept or reject proposed chages to the constrained property in the
           source bean.
       • A PropertyChangeEvent object containing the property name, its old value and new values.


8. Bound Bean Property:
   A Bean that has a bound property generates an event when the property is changed. The event is of the
   type PropertyChangeEvent and it is sent to the objects that have registered for this event notification.


What is Persistence in the context of JavaBeans?
Persistence is the ability to save a Bean to nonvolatile storage (disk) and retrieve it at a later time.
Configuration settings are important and are saved this way.


Prof. Mukesh N. Tekwani                                                                       Page 3 of 8
Java Beans

Java class libraries have object serialization capabilities. Serialization is the process of writing the state of
an object to a byte stream (file). A Bean must implement the java.io.Serializable interface. This makes
serialization automatic.

Write short note on JAR files? What are the options available with JAR file?

1. JAR – Java Archive
2. A Jar file has the extension .jar.
3. It is a compressed file that contains classes and other resources which are required to use beans. The
   Jar files can contain videos files, image files, audio files, etc.,
4. BDK expect Beans to be packaged within JAR files.
5. A JAR file allows you to efficiently deploy a set of classes and their associated resources. For
   example, a developer may build a multimedia application that uses various sound and image files. A
   set of Beans can control how and when this information is presented. All of these pieces can be placed
   into one JAR file.
6. The elements in a JAR file are compressed and so downloading a JAR file is faster than downloading
   several uncompressed files.
7. Digital signatures can also be associated with the individual elements in a JAR file. This allows a
   consumer to be sure that these elements were produced by a specific organization or individual.

The jar utility is : jar options file

Example: Create a JAR file named XYZ.Jar that contains all the .class and .gif files in the current
directory.

         jar cf Xyz.jar *.class *.gif

Options available with jar:

Option            Description
c                 A new archive is to be created.
C                 Change directories during command execution.
f                 The first element in the file list is the name of the
                  archive that is to be created or accessed.
i                 Index information should be provided.
m                 The second element in the file list is the name of the
                  external manifest file.
M                 Manifest file not created.
t                 The archive contents should be tabulated.
u                 Update existing JAR file.
v                 Verbose output should be provided by the utility as it
                  executes.
x                 Files are to be extracted from the archive.
0                 Do not use compression.

Examples:
Tabulating the Contents of a jar file:
jar tf Xyz.jar
Extracting files from a jar file:
jar xf Xyz.jar

Page 4 of 8                                                                     mukeshtekwani@hotmail.com
Java Beans

Updating an existing jar file:
jar –uf Xyz.jar file1.class


What is the manifest file?

1. A manifest file is a text file which contains the descriptions of the beans contained in the JAR files.
2. A manifest file indicates which of the components in a JAR file are Java Beans. An example of a
   manifest file is this: The JAR file contains four .gif files and one .class file. The last entry is a Bean.
      Name: slide0.gif
      Name: slide1.gif
      Name: slide2.gif
      Name: slide3.gif
      Name: Slides.class
      Java-Bean: True
3. A manifest file may reference many.class files. If a .class file is a Java Bean, its entry must be
   immediately followed by the line “Java-Bean: True”.

Explain the BeanInfo interface.

    1. There are two ways to determine what information is available to the user of a Bean.
    2. One way is through the design patterns. The design pattern implicitly determines what properties
       are available to the user.
    3. The other way is by using the BeanInfo interface.
    4. The BeanInfo interface allows the programmer to explicitly control what information is available.
    5. The methods of BeanINfo interface are:
               PropertyDescriptor [] getPropertyDescriptors()
               EventSetDescriptor [] getEventSetyDescriptors()
               MethodDescriptor [] getMethodDescriptors()
    6. All these methods return an array of objects that provide information about properties, events and
       methods of a Bean.
    7. The classes PropertyDescriptor, EventSetDescriptor, and MethodDescriptor are defined in the
       java.beans package.
    8. When creating a class that implements BeamInfo, we must give it the name bnameBeamInfo,
       where bname is the name of the Bean. E.g., MyBeanBeanInfo.

Discuss the following classes of JavaBeans API: Introspector, PropertyDescriptor,
EventSetDescriptor, and MethodDescriptor

Introspector Class: This class provides methods that support introspection. The most important one is
the getBeanInfo() method. This method returns a BeanInfo object that can be used to obtain information
about the Bean.

PropertyDescriptor Class: This class describes the Bean properties. It has many methods that can
manage and describe properties. E.g., we can determine if a property is bound by calling the isBound()
method. Similarly there is a method isConstrained(). To get the name of the property we use the
getName() method.

EventSetDescriptor: This class represents a Bean event. Methods of this class are:
getAddListenerMethod() – this is used to obtain the methods used to add listeners; the
getRemoveListenerMethod() is used to obtain methods used to remove listeners.


Prof. Mukesh N. Tekwani                                                                          Page 5 of 8
Java Beans

MethodDescriptor: This class represents a Bean method. We can use the method getName() to obtain the
name of a method.

                                           PROGRAMS

1. Write JavaBean program that finds square and cube value in terms of properties.

public class mathcalc
{
     int a;

       public mathcalc() { }

       public void setA(int m)
       {
            a = m;
       }

       public int getA()
       {
            return (a);
       }

       public int getSquare()
       {
            return (a * a);
       }

       public void setSquare( int m)                 { }

       public int getCube()
       {
            return (a * a * a);
       }

       public void setCube( int m)                   { }

2. Write JavaBean program to find the sum, difference, product and ratio of two numbers as
   properties.

public class cal                                             public void setA(int m)
{                                                            {
     int a, b;                                                    a = m;
                                                             }
       public cal()
       {                                                     public int getB()
            a = 0; b = 1;                                    {
       }                                                          return b;
                                                             }
       public int getA()
       {                                                     public void setB(int n)
            return a;                                        {
       }                                                          b = n;
                                                             }
Page 6 of 8                                                            mukeshtekwani@hotmail.com
Java Beans


       public int getAdd()                                public int getMul()
       {                                                  {
            return (a + b);                                    return (a * b);
       }                                                  }

       public void setAdd(int m){ }                       public void setMul(int m) { }

       public int getSub()                                public int getDiv()
       {                                                  {
            return (a - b);                                    return (a / b);
       }                                           }

       public void setSub(int m) { }                      public void setDiv(int m) { }


3. Write JavaBean program to find the reverse of a number as a property.

public class revno
{
     int n;

       public revno() {}

       public int getN()
       {
            return n;
       }

       public void setN(int m)
       {
            n = m;
       }

       public int getRevNo()
       {
            int d, revnum = 0;
            int temp = n;

              while (temp > 0)
              {
                   d = temp % 10;
                   revnum = (revnum * 10) + d;
                   temp = temp / 10;
              }

              return revnum;
       }

       public void setRevNum(int m){}
}




Prof. Mukesh N. Tekwani                                                        Page 7 of 8
Java Beans

4. Write multiline JavaBean program.
In this program we use TextArea for multiline text.

import java.awt.*;
import java.awt.event.*;

public class multiline extends Panel
{
     int height, width;
     TextArea ta;

        public multiline()
        {
             TextArea ta = new TextArea(5, 50);

                add(ta);

                ta.setText(“Learning Java Beans” +
                           “n From Internet resources” +
                           “n and books”);
                setSize(300, 300);
                setVisible(true);
        }

        public int getheight()
        {
             return height;
        }

        public void setheight(int h)
        {
             height = h;
             setSize(width, height);
        }

        public int getwidth()
        {
             return width;
        }

        public void setwidth(int w)
        {
             width = w;
             setSize(width, height);
        }
}




Page 8 of 8                                             mukeshtekwani@hotmail.com

More Related Content

What's hot

Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Java beans
Java beansJava beans
Java beans
Rajkiran Mummadi
 
Android Fragment
Android FragmentAndroid Fragment
Android Fragment
Kan-Han (John) Lu
 
Visual Basic menu
Visual Basic menuVisual Basic menu
Visual Basic menu
kuldeep94
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
Tareq Hasan
 
React js
React jsReact js
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
Yao Nien Chung
 
Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
Adil Mehmoood
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
ARSLANMEHMOOD47
 
Unit iv
Unit ivUnit iv
Unit iv
bhushan_adavi
 
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Net
rishisingh190
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
prabhu rajendran
 
VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedurepragya ratan
 
Android graphics
Android graphicsAndroid graphics
Android graphicsKrazy Koder
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
Awt
AwtAwt
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 

What's hot (20)

Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Java beans
Java beansJava beans
Java beans
 
Android Fragment
Android FragmentAndroid Fragment
Android Fragment
 
Visual Basic menu
Visual Basic menuVisual Basic menu
Visual Basic menu
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
React js
React jsReact js
React js
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
 
Event handling
Event handlingEvent handling
Event handling
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
 
Unit iv
Unit ivUnit iv
Unit iv
 
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Net
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedure
 
Android graphics
Android graphicsAndroid graphics
Android graphics
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Awt
AwtAwt
Awt
 
Applets in java
Applets in javaApplets in java
Applets in java
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 

Similar to Java beans

Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
Neelesh Shukla
 
Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)
SURBHI SAROHA
 
Classes, Inheritance ,Packages & Interfaces.pptx
Classes, Inheritance ,Packages & Interfaces.pptxClasses, Inheritance ,Packages & Interfaces.pptx
Classes, Inheritance ,Packages & Interfaces.pptx
DivyaKS18
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
Implementation of interface9 cm604.30
Implementation of interface9 cm604.30Implementation of interface9 cm604.30
Implementation of interface9 cm604.30myrajendra
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoM
ambikavenkatesh2
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
nurkhaledah
 
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)uEngine Solutions
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
Lakshmi Sarvani Videla
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
Donald Sipe
 
Chapter 13 introduction to classes
Chapter 13 introduction to classesChapter 13 introduction to classes
Chapter 13 introduction to classes
rsnyder3601
 
Chapter 04 inheritance
Chapter 04 inheritanceChapter 04 inheritance
Chapter 04 inheritance
Nurhanna Aziz
 
Object
ObjectObject
1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdf1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdf
archgeetsenterprises
 

Similar to Java beans (20)

Bean Intro
Bean IntroBean Intro
Bean Intro
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)
 
Classes, Inheritance ,Packages & Interfaces.pptx
Classes, Inheritance ,Packages & Interfaces.pptxClasses, Inheritance ,Packages & Interfaces.pptx
Classes, Inheritance ,Packages & Interfaces.pptx
 
class and objects
class and objectsclass and objects
class and objects
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Implementation of interface9 cm604.30
Implementation of interface9 cm604.30Implementation of interface9 cm604.30
Implementation of interface9 cm604.30
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoM
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
 
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Javabean1
Javabean1Javabean1
Javabean1
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Chapter 13 introduction to classes
Chapter 13 introduction to classesChapter 13 introduction to classes
Chapter 13 introduction to classes
 
Chapter 04 inheritance
Chapter 04 inheritanceChapter 04 inheritance
Chapter 04 inheritance
 
Object
ObjectObject
Object
 
1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdf1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdf
 
Metaworks3
Metaworks3Metaworks3
Metaworks3
 

More from Mukesh Tekwani

Computer Science Made Easy - Youtube Channel
Computer Science Made Easy - Youtube ChannelComputer Science Made Easy - Youtube Channel
Computer Science Made Easy - Youtube Channel
Mukesh Tekwani
 
The Elphinstonian 1988-College Building Centenary Number (2).pdf
The Elphinstonian 1988-College Building Centenary Number (2).pdfThe Elphinstonian 1988-College Building Centenary Number (2).pdf
The Elphinstonian 1988-College Building Centenary Number (2).pdf
Mukesh Tekwani
 
Circular motion
Circular motionCircular motion
Circular motion
Mukesh Tekwani
 
Gravitation
GravitationGravitation
Gravitation
Mukesh Tekwani
 
ISCE-Class 12-Question Bank - Electrostatics - Physics
ISCE-Class 12-Question Bank - Electrostatics  -  PhysicsISCE-Class 12-Question Bank - Electrostatics  -  Physics
ISCE-Class 12-Question Bank - Electrostatics - Physics
Mukesh Tekwani
 
Hexadecimal to binary conversion
Hexadecimal to binary conversion Hexadecimal to binary conversion
Hexadecimal to binary conversion
Mukesh Tekwani
 
Hexadecimal to decimal conversion
Hexadecimal to decimal conversion Hexadecimal to decimal conversion
Hexadecimal to decimal conversion
Mukesh Tekwani
 
Hexadecimal to octal conversion
Hexadecimal to octal conversionHexadecimal to octal conversion
Hexadecimal to octal conversion
Mukesh Tekwani
 
Gray code to binary conversion
Gray code to binary conversion Gray code to binary conversion
Gray code to binary conversion
Mukesh Tekwani
 
What is Gray Code?
What is Gray Code? What is Gray Code?
What is Gray Code?
Mukesh Tekwani
 
Decimal to Binary conversion
Decimal to Binary conversionDecimal to Binary conversion
Decimal to Binary conversion
Mukesh Tekwani
 
Video Lectures for IGCSE Physics 2020-21
Video Lectures for IGCSE Physics 2020-21Video Lectures for IGCSE Physics 2020-21
Video Lectures for IGCSE Physics 2020-21
Mukesh Tekwani
 
Refraction and dispersion of light through a prism
Refraction and dispersion of light through a prismRefraction and dispersion of light through a prism
Refraction and dispersion of light through a prism
Mukesh Tekwani
 
Refraction of light at a plane surface
Refraction of light at a plane surfaceRefraction of light at a plane surface
Refraction of light at a plane surface
Mukesh Tekwani
 
Spherical mirrors
Spherical mirrorsSpherical mirrors
Spherical mirrors
Mukesh Tekwani
 
Atom, origin of spectra Bohr's theory of hydrogen atom
Atom, origin of spectra Bohr's theory of hydrogen atomAtom, origin of spectra Bohr's theory of hydrogen atom
Atom, origin of spectra Bohr's theory of hydrogen atom
Mukesh Tekwani
 
Refraction of light at spherical surfaces of lenses
Refraction of light at spherical surfaces of lensesRefraction of light at spherical surfaces of lenses
Refraction of light at spherical surfaces of lenses
Mukesh Tekwani
 
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGEISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
Mukesh Tekwani
 
Cyber Laws
Cyber LawsCyber Laws
Cyber Laws
Mukesh Tekwani
 
XML
XMLXML

More from Mukesh Tekwani (20)

Computer Science Made Easy - Youtube Channel
Computer Science Made Easy - Youtube ChannelComputer Science Made Easy - Youtube Channel
Computer Science Made Easy - Youtube Channel
 
The Elphinstonian 1988-College Building Centenary Number (2).pdf
The Elphinstonian 1988-College Building Centenary Number (2).pdfThe Elphinstonian 1988-College Building Centenary Number (2).pdf
The Elphinstonian 1988-College Building Centenary Number (2).pdf
 
Circular motion
Circular motionCircular motion
Circular motion
 
Gravitation
GravitationGravitation
Gravitation
 
ISCE-Class 12-Question Bank - Electrostatics - Physics
ISCE-Class 12-Question Bank - Electrostatics  -  PhysicsISCE-Class 12-Question Bank - Electrostatics  -  Physics
ISCE-Class 12-Question Bank - Electrostatics - Physics
 
Hexadecimal to binary conversion
Hexadecimal to binary conversion Hexadecimal to binary conversion
Hexadecimal to binary conversion
 
Hexadecimal to decimal conversion
Hexadecimal to decimal conversion Hexadecimal to decimal conversion
Hexadecimal to decimal conversion
 
Hexadecimal to octal conversion
Hexadecimal to octal conversionHexadecimal to octal conversion
Hexadecimal to octal conversion
 
Gray code to binary conversion
Gray code to binary conversion Gray code to binary conversion
Gray code to binary conversion
 
What is Gray Code?
What is Gray Code? What is Gray Code?
What is Gray Code?
 
Decimal to Binary conversion
Decimal to Binary conversionDecimal to Binary conversion
Decimal to Binary conversion
 
Video Lectures for IGCSE Physics 2020-21
Video Lectures for IGCSE Physics 2020-21Video Lectures for IGCSE Physics 2020-21
Video Lectures for IGCSE Physics 2020-21
 
Refraction and dispersion of light through a prism
Refraction and dispersion of light through a prismRefraction and dispersion of light through a prism
Refraction and dispersion of light through a prism
 
Refraction of light at a plane surface
Refraction of light at a plane surfaceRefraction of light at a plane surface
Refraction of light at a plane surface
 
Spherical mirrors
Spherical mirrorsSpherical mirrors
Spherical mirrors
 
Atom, origin of spectra Bohr's theory of hydrogen atom
Atom, origin of spectra Bohr's theory of hydrogen atomAtom, origin of spectra Bohr's theory of hydrogen atom
Atom, origin of spectra Bohr's theory of hydrogen atom
 
Refraction of light at spherical surfaces of lenses
Refraction of light at spherical surfaces of lensesRefraction of light at spherical surfaces of lenses
Refraction of light at spherical surfaces of lenses
 
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGEISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
 
Cyber Laws
Cyber LawsCyber Laws
Cyber Laws
 
XML
XMLXML
XML
 

Recently uploaded

The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 

Recently uploaded (20)

The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 

Java beans

  • 1. Java Beans JAVA BEANS What are Java Beans? 1. A Java Bean is a software component that is designed to be reusable. 2. It is a java class that has a zero-argument (empty) constructor. So we can either not specify a constructor at all, or define a constructor with no arguments. 3. JavaBean class has no public instance variables (fields). Therefore we have to use the accessor methods instead of allowing direct access to the private fields. 4. Values are accessed through methods called as getXXX and setXXX. If a class has a method getTitle that returns a string, the class is said to have a String property named Title. 5. 6. A bean may perform a simple function, such as checking the spelling of a document, or a complex function, such as forecasting the performance of a stock portfolio. 7. A Bean may be visible to an end user, e.g., a button on a graphical user interface. A Bean may also be invisible to a user, e.g., software to decode a stream of multimedia information in real time. 8. A Bean may be designed to work autonomously on a user’s workstation or to work in cooperation with a set of other distributed components. E.g., software to generate a pie chart from a set of data points is an example of a Bean that can execute locally. However, a Bean that provides real-time price information from a stock will have to work in cooperation with other distributed software to obtain its data. What are the advantages of using Java beans? 1. A Bean has all the benefits of Java’s “write-once, run-anywhere” paradigm. 2. We can control which properties, events, and methods of a Bean are available to an application builder. 3. A Bean may be designed to operate correctly in different locales (environments), and are therefore useful in global markets. 4. Auxiliary software can be provided to help a person configure a Bean. This software is only needed when the design-time parameters for that component are being set. It does not need to be included in the run-time environment. 5. The configuration settings of a Bean can be saved in persistent storage and restored at a later time. 6. A Bean may register to receive events from other objects and can generate events that are sent to other objects. Explain the term “introspection” in the context of Java Beans. 1. Introspection is the process of analyzing a Bean to determine its capabilities. This is an important feature of the Java Beans API, because it allows an application builder tool to obtain information about a component. 2. There are two ways in which the developer of a Bean can indicate which of its properties, events, and methods should be exposed by an application builder tool. 3. In the first method, simple naming conventions are used. These allow the introspection mechanisms to infer information about a Bean. 4. In the second way, an additional class is provided that explicitly supplies this information. 5. Design Pattern for Properties: a. A design pattern specifies the rules for forming the method signature, return type and even its name. Design patterns can provide a useful documentation hint for programmers. b. The major design patterns are: i. Property design pattern, ii. Event design pattern, and iii. Method design pattern Prof. Mukesh N. Tekwani Page 1 of 8
  • 2. Java Beans c. A property is a named attribute. It specifies the characteristic, behavior and state of the object. Properties are functions which can get or set the values of a variable. A property is a subset of a Bean’s state. The values assigned to the properties determine the behavior and appearance of the component. d. Property design patterns are used to identify the publicly accessible properties of a bean. e. The setter method is used to set a property and the getter method is used to obtain the property. f. If a property has only a getter method, JavaBeans assumes that it is a read-only property. If both getter and setter methods are defined, JavaBeans assumes it is a read-write property. g. There are three types of properties: simple, Boolean and indexed. h. Simple Properties: A simple property has a single value. The following design pattern is used: public T getN() public void setN(T arg) Here N is the name of the property and T is its type. A read/write property has both these methods to access its value. A read-only property has only the get method. The write-only property has only the set method. Example: } private double depth, height, width; public double setDepth(double d) public double getDepth() { { depth = d; return depth; } public double getHeight() public double getWidth() { { return height; return width; } } public double setHeightdouble h) public double setWidth(double w) { { height = h; width = w; } } i. Boolean Properties: The design pattern is as follows: public Boolean isN( ); public void setN(Boolean a); j. Indexed Properties: An indexed property consists of multiple values, i.e,, it is an array of simple properties. It has the following design pattern: public T getN (int index); public void setN (int index, T value); public T [ ] getN (); public void setN (T values[]); Consider an indexed property data. Its getter and setter methods are shown below: private double data [ ]; Page 2 of 8 mukeshtekwani@hotmail.com
  • 3. Java Beans public double getData(int index) public double [ ] getData() { { return data[index]; return data; } } public void setData(int index double value) public void setData(double [ ] { values) data [index] = value; { } data = new double[values.length]; System.arraycopy(values, 0, data, 0, values.length); } 6. Design Pattern for Events: When a Bean’s internal state changes, it is often necessary to inform the other object of the change. Beans can do this by communicating events with other objects. Beans send event notifications to event listeners that have registered themselves with a bean. Beans use the delegation event model. An event is generated by the bean and sent to other objects. public void addTListener(TListener eventListener); public void removeTListener(TListener eventListener); These methods are used to add or remove a listener for the specified event. For example, to add support for event listener that implements the ActionListener interface, we write: public void addActionListener(ActionListener al); public void removeActionListener(ActionListener al); TheActionListener interface is used to receive actions like mouse clicks. 7. Constrained Bean Property: A Bean property is constrained when any change to that property can be prevented. The Bean can itself prevent a property change. The 3 parts of a constrained property implementation are: • A source bean containing constrained properties. • Listener object that can accept or reject proposed chages to the constrained property in the source bean. • A PropertyChangeEvent object containing the property name, its old value and new values. 8. Bound Bean Property: A Bean that has a bound property generates an event when the property is changed. The event is of the type PropertyChangeEvent and it is sent to the objects that have registered for this event notification. What is Persistence in the context of JavaBeans? Persistence is the ability to save a Bean to nonvolatile storage (disk) and retrieve it at a later time. Configuration settings are important and are saved this way. Prof. Mukesh N. Tekwani Page 3 of 8
  • 4. Java Beans Java class libraries have object serialization capabilities. Serialization is the process of writing the state of an object to a byte stream (file). A Bean must implement the java.io.Serializable interface. This makes serialization automatic. Write short note on JAR files? What are the options available with JAR file? 1. JAR – Java Archive 2. A Jar file has the extension .jar. 3. It is a compressed file that contains classes and other resources which are required to use beans. The Jar files can contain videos files, image files, audio files, etc., 4. BDK expect Beans to be packaged within JAR files. 5. A JAR file allows you to efficiently deploy a set of classes and their associated resources. For example, a developer may build a multimedia application that uses various sound and image files. A set of Beans can control how and when this information is presented. All of these pieces can be placed into one JAR file. 6. The elements in a JAR file are compressed and so downloading a JAR file is faster than downloading several uncompressed files. 7. Digital signatures can also be associated with the individual elements in a JAR file. This allows a consumer to be sure that these elements were produced by a specific organization or individual. The jar utility is : jar options file Example: Create a JAR file named XYZ.Jar that contains all the .class and .gif files in the current directory. jar cf Xyz.jar *.class *.gif Options available with jar: Option Description c A new archive is to be created. C Change directories during command execution. f The first element in the file list is the name of the archive that is to be created or accessed. i Index information should be provided. m The second element in the file list is the name of the external manifest file. M Manifest file not created. t The archive contents should be tabulated. u Update existing JAR file. v Verbose output should be provided by the utility as it executes. x Files are to be extracted from the archive. 0 Do not use compression. Examples: Tabulating the Contents of a jar file: jar tf Xyz.jar Extracting files from a jar file: jar xf Xyz.jar Page 4 of 8 mukeshtekwani@hotmail.com
  • 5. Java Beans Updating an existing jar file: jar –uf Xyz.jar file1.class What is the manifest file? 1. A manifest file is a text file which contains the descriptions of the beans contained in the JAR files. 2. A manifest file indicates which of the components in a JAR file are Java Beans. An example of a manifest file is this: The JAR file contains four .gif files and one .class file. The last entry is a Bean. Name: slide0.gif Name: slide1.gif Name: slide2.gif Name: slide3.gif Name: Slides.class Java-Bean: True 3. A manifest file may reference many.class files. If a .class file is a Java Bean, its entry must be immediately followed by the line “Java-Bean: True”. Explain the BeanInfo interface. 1. There are two ways to determine what information is available to the user of a Bean. 2. One way is through the design patterns. The design pattern implicitly determines what properties are available to the user. 3. The other way is by using the BeanInfo interface. 4. The BeanInfo interface allows the programmer to explicitly control what information is available. 5. The methods of BeanINfo interface are: PropertyDescriptor [] getPropertyDescriptors() EventSetDescriptor [] getEventSetyDescriptors() MethodDescriptor [] getMethodDescriptors() 6. All these methods return an array of objects that provide information about properties, events and methods of a Bean. 7. The classes PropertyDescriptor, EventSetDescriptor, and MethodDescriptor are defined in the java.beans package. 8. When creating a class that implements BeamInfo, we must give it the name bnameBeamInfo, where bname is the name of the Bean. E.g., MyBeanBeanInfo. Discuss the following classes of JavaBeans API: Introspector, PropertyDescriptor, EventSetDescriptor, and MethodDescriptor Introspector Class: This class provides methods that support introspection. The most important one is the getBeanInfo() method. This method returns a BeanInfo object that can be used to obtain information about the Bean. PropertyDescriptor Class: This class describes the Bean properties. It has many methods that can manage and describe properties. E.g., we can determine if a property is bound by calling the isBound() method. Similarly there is a method isConstrained(). To get the name of the property we use the getName() method. EventSetDescriptor: This class represents a Bean event. Methods of this class are: getAddListenerMethod() – this is used to obtain the methods used to add listeners; the getRemoveListenerMethod() is used to obtain methods used to remove listeners. Prof. Mukesh N. Tekwani Page 5 of 8
  • 6. Java Beans MethodDescriptor: This class represents a Bean method. We can use the method getName() to obtain the name of a method. PROGRAMS 1. Write JavaBean program that finds square and cube value in terms of properties. public class mathcalc { int a; public mathcalc() { } public void setA(int m) { a = m; } public int getA() { return (a); } public int getSquare() { return (a * a); } public void setSquare( int m) { } public int getCube() { return (a * a * a); } public void setCube( int m) { } 2. Write JavaBean program to find the sum, difference, product and ratio of two numbers as properties. public class cal public void setA(int m) { { int a, b; a = m; } public cal() { public int getB() a = 0; b = 1; { } return b; } public int getA() { public void setB(int n) return a; { } b = n; } Page 6 of 8 mukeshtekwani@hotmail.com
  • 7. Java Beans public int getAdd() public int getMul() { { return (a + b); return (a * b); } } public void setAdd(int m){ } public void setMul(int m) { } public int getSub() public int getDiv() { { return (a - b); return (a / b); } } public void setSub(int m) { } public void setDiv(int m) { } 3. Write JavaBean program to find the reverse of a number as a property. public class revno { int n; public revno() {} public int getN() { return n; } public void setN(int m) { n = m; } public int getRevNo() { int d, revnum = 0; int temp = n; while (temp > 0) { d = temp % 10; revnum = (revnum * 10) + d; temp = temp / 10; } return revnum; } public void setRevNum(int m){} } Prof. Mukesh N. Tekwani Page 7 of 8
  • 8. Java Beans 4. Write multiline JavaBean program. In this program we use TextArea for multiline text. import java.awt.*; import java.awt.event.*; public class multiline extends Panel { int height, width; TextArea ta; public multiline() { TextArea ta = new TextArea(5, 50); add(ta); ta.setText(“Learning Java Beans” + “n From Internet resources” + “n and books”); setSize(300, 300); setVisible(true); } public int getheight() { return height; } public void setheight(int h) { height = h; setSize(width, height); } public int getwidth() { return width; } public void setwidth(int w) { width = w; setSize(width, height); } } Page 8 of 8 mukeshtekwani@hotmail.com