| Author |
Serialization in java
|
kiruthigha rajan
Ranch Hand
Joined: Dec 29, 2011
Posts: 69
|
|
hai im having some doubts in this program:
1)why we have used writeInt in line three?what it does and what is the use of this in this program?
2)does the methods writeObject(ObjectOutputStream os) and readObject(ObjectInputStream is) is the altenative of
and
please explain me in detail thanks in advance
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
kiruthigha rajan wrote:
1)why we have used writeInt in line three?what it does and what is the use of this in this program?
First, we can only speculate -- as we don't have any context on what is the implementation for.
It looks like programmer don't want to serialize the Collar object -- the comment states that it isn't possible to serialize it.... However, the Dog object needs it. And it looks like it is possible to simply get another Collar upon deserialization -- provided the collar size is correct. So, the programmer sent the dog collar size as part of the serialized stream.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
No. This is not an alternative. The first snippet is a modification on how the object should be serialized (specifically the components related to the Dog class only). This set of snippets is the actual serialization and deserialization of the object. This set of code will call the other set of code when it is time to serialize the Dog class component of the Dog object.
Henry
|
 |
kiruthigha rajan
Ranch Hand
Joined: Dec 29, 2011
Posts: 69
|
|
what is the difference between writeObject(),readObject() and defaultWriteObject(),defaultReadObject()?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Sun has a decent article that describes everything.
http://java.sun.com/developer/technicalArticles/Programming/serialization/
It's certainly better than learning it piecemeal via forum exchanges.
Henry
|
 |
 |
|
|
subject: Serialization in java
|
|
|