SlideShare une entreprise Scribd logo
1  sur  8
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances (20)

Java beans
Java beansJava beans
Java beans
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Java swing
Java swingJava swing
Java swing
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Java servlets
Java servletsJava servlets
Java servlets
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
Java beans
Java beansJava beans
Java beans
 
Session bean
Session beanSession bean
Session bean
 
Servlets
ServletsServlets
Servlets
 
JNDI
JNDIJNDI
JNDI
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
Consuming Web Services in Android
Consuming Web Services in AndroidConsuming Web Services in Android
Consuming Web Services in Android
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
 
Java rmi
Java rmiJava rmi
Java rmi
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 

Similaire à Java beans

Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programmingNeelesh 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
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
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,UoMambikavenkatesh2
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vectornurkhaledah
 
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)uEngine Solutions
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfacesmadhavi patil
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptDonald Sipe
 
Chapter 13 introduction to classes
Chapter 13 introduction to classesChapter 13 introduction to classes
Chapter 13 introduction to classesrsnyder3601
 
Chapter 04 inheritance
Chapter 04 inheritanceChapter 04 inheritance
Chapter 04 inheritanceNurhanna Aziz
 
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.pdfarchgeetsenterprises
 

Similaire à 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)
 
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
 
Mattbrenner
MattbrennerMattbrenner
Mattbrenner
 

Plus de Mukesh Tekwani

Computer Science Made Easy - Youtube Channel
Computer Science Made Easy - Youtube ChannelComputer Science Made Easy - Youtube Channel
Computer Science Made Easy - Youtube ChannelMukesh 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).pdfMukesh 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 - PhysicsMukesh 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 conversionMukesh Tekwani
 
Gray code to binary conversion
Gray code to binary conversion Gray code to binary conversion
Gray code to binary conversion Mukesh Tekwani
 
Decimal to Binary conversion
Decimal to Binary conversionDecimal to Binary conversion
Decimal to Binary conversionMukesh 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-21Mukesh 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 prismMukesh 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 surfaceMukesh 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 atomMukesh 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 lensesMukesh 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 - WEIGHTAGEMukesh Tekwani
 

Plus de 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
 

Dernier

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 

Dernier (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

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