Can anyone pls help me to understand the serialization mechanism in details.
posted 8 years ago
It is very hard to explain serialization mechanism in details in a forum. Try to be more specific. What exactly don't you understand about serialization. You can use the following just as guidelines.
1) Serialization is a powerful technique that allows you to write and read the state of the object to and from text files.
2) Instance variables that is marked as transient are not serializable meaning that they cannot be written or read from text files.
3) Any class that is to be serialized or de-serialized must implement the serializable interface which is a marker interface with no methods to implement.
4) All classes that exhibit has-a relationship must implement the serializable interface if the class is to be serialized. Otherwise, an exception is thrown at runtime and the objects cannot be serialized.
5) All classes that exhibit is-a relationship must not implement the serializable interface if the object is to be serialized. You can remember that by the fact that the Object class does not implement serializable and yet all the subclasses are able to implement it. However, if they don't implement serializable, then when the super() is called, the instance variables return to their default values.
6) you can override the writeObject and readObject methods in order to write and read Objects to text files in a specific way.