File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialization Mechanism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serialization Mechanism" Watch "Serialization Mechanism" New topic

Serialization Mechanism

Ritu Kapoor
Ranch Hand

Joined: Oct 03, 2004
Posts: 102
Can anyone pls help me to understand the serialization mechanism in details.

Raef Kandeel
Ranch Hand

Joined: Aug 05, 2007
Posts: 87
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.

I agree. Here's the link:
subject: Serialization Mechanism
It's not a secret anymore!