Developing Java Beans When an object is saved,
Developing Java Beans When an object is saved, its internal data members are saved along with any other objects that it refers to. The resulting serialized data contains information about the types and classes of the objects, as well as their values. There is enough information stored to be able to reconstruct the objects with their values at a later time, including any references to other objects. In some cases, one object can be referenced by more than one other object. The serialization mechanism keeps track of objects efficiently so that if multiple references to an object exist, the object is only stored once. This is important when the objects are reconstructed from the serialized data, ensuring that there is only one new instance of the object that is referenced by others. Let’s look at an example. import java.io.*; class WidgetA implements Serializable{ protected int val; public WidgetA() { } public void setValue(int value) { val = value; } public int getValue() { return val; } } class WidgetB implements Serializable { protected int val; protected WidgetA AA; public WidgetB(WidgetA a) { AA = a; } public void setValue(int value) { val = value; } public int getValue() { return val; } } class Container implements Serializable { protected int val; protected WidgetA a1; protected WidgetB b1; public Container() { a1 = new WidgetA(); b1 = new WidgetB(a1); } page 75