Java Beans questions for Computer Science and MCA students

Write a note on Rules for writing Java bean class.

The java beans provide a standard format for writing the java classes. It is a reusable software component. Once it is designed and created it can be reused over an over again as per the requirements.

Following are the rules or guidelines for writing a java bean class:
  • A bean class should have a no-argument constructor.
  • It should have no public properties.
  • The properties should be modified and accessed through the setter (setXXX) and getter (getXXX) methods.
  • The introspection is which supports and allows a builder tool to analyze how a bean works.
  • The customization supports and allows the users to alter the appearance and behavior of a bean.
  • The supporting beans allow the beans to fire the events and inform the application builder tools about the events they can fire and handle.
  • The persistence supports and allows the beans to be customized in an application builder tool to have their state saved and later restored.

Write a note on Beans persistence.

  • A bean has the property of persistence when its properties, fields, and state information are saved to and retrieved from storage.
  • Component models provide a mechanism for persistence that enables the state of components to be stored in a non-volatile place for later retrieval.
  • The mechanism that makes persistence possible is called serialization. Object serialization means converting an object into a data stream and writing it to storage.
  • Any applet, application, or tool that uses that bean can then "reconstitute" it by deserialization. The object is then restored to its original state.
  • For example, a Java application can serialize a Frame window on a Microsoft Windows machine, the serialized file can be sent with e-mail to a Solaris machine, and then a Java application can restore the Frame window to the exact state which existed on the Microsoft Windows machine.
  • Any applet, application, or tool that uses that bean can then "reconstitute" it by deserialization.
  • All beans must persist. To persist, your beans must support serialization by implementing either the java.io.Serializable (in the API reference documentation) interface, or the java.io.Externalizable (in the API reference documentation) interface.
  • These interfaces offer you the choices of automatic serialization and customized serialization. If any class in a class's inheritance hierarchy implements Serializable or Externalizable, then that class is serializable.