• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is Serialization?

 
Rakesh Mehra
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is Serialization?When and how do we implement it?Example real time environment application that uses Serialization?
 
abhishek pendkay
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serialization
visit this page for all the info you need
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For what is serialization you can read the link given above. Moreover, you can google serialization.

Implementing Serializable is bit tricky not that difficult though. YOu just need to take care of few things. Mainly, over-riding of readObject() method. For more you can refer to the book Effective Java from Joshua Bloch or try this link out.

Serilization is used in many ways when we need to send the objects over the network, or persist the objects on to storage device, etc.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adeel Ansari:
Mainly, over-riding of readObject() method.

First of all, readObject is private so it isn't overridden. Instead, it is re-implemented.

Second, you only need readObject (and its partner in crime, writeObject) if you need to do some custom serialization, like serializing fields of a parent class that isn't serializable.


If you let a class implement java.io.Serializable, all primitive fields and serializable fields are serialized without any extra work. It's only when you need to store non-serializable fields or do any other custom work when readObject and writeObject come into play.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
First of all, readObject is private so it isn't overridden. Instead, it is re-implemented.


Thanks for the correction. You can think of readObject() as a constructor whose sole argument is a byte stream.

Furthermore, making your class serializable is not a decision to be taken lightly.

Thanks.
[ November 27, 2007: Message edited by: Adeel Ansari ]
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just some more data on previous responses...

Originally posted by Rob Prime:

... you only need readObject (and its partner in crime, writeObject) if you need to do some custom serialization, ...


including supporting over versions of your object,

for example, if you were using a data object to represent your document, and you updated the structure, you might want to be able to readObject() from old versions, then when you writeObject() it would be updated
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic