Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialization/Deserialization

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a class which implement Serializable. I Serialize it on JVM. In the process of Serialization, the following occurs

Everytime an object is serialized the java serialization mechanism automatically computes a hash value. ObjectStreamClass's computeSerialVersionUID() method passes the class name, sorted member names, modifiers, and interfaces to the secure hash algorithm (SHA), which returns a hash value.The serialVersionUID is also called suid.
So when the serilaize object is retrieved , the JVM first evaluates the suid of the serialized class and compares the suid value with the one of the object. If the suid values match then the object is said to be compatible with the class and hence it is de-serialized. If not InvalidClassException exception is thrown.

Now if i Serialize using JVM1 and Deserialize using JVM2, then will the Deserialization work successfully. Also how does Serialization/Deserialization works across network, because when the object is transported across network the JVMs might be different.
 
Hrishikesh Yeshwant Alshi
Ranch Hand
Posts: 62
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how serialization happens:


Java in memory object ---> Serialized ---> Written ---> Stream

Java in memory object <--- de-serialized <--- Read <--- Stream

Stream can be anything, like, output stream, error stream, file output stream or socket (as a network stream)

During writing and reading a protocol is followed which is independent of JVM. I mean, An object serialized by one JVM can be de-serialized by other JVM without any problem.

The process of writing the object on the network stream is called marshalling and reading from the network stream is called un-marshalling.

You can check out this site for details and diagrams.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Hrishikesh. The article on Java serialization algorithm was very helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic