Please refer example on page 467 of Kathy Seirra and Bert Bates SCJP 6 Book. following is a part of the code from the example on the aforementioned page.
My question is that when we are serializing the dog object the serialization system calls the callback private writeObject method and passed it the ObjectOutputStream. but when we did os.writeInt(theCollar.getCollarSize()); how did it know which Dog's object Collar we are talking about, because we are not passing any dog reference explicitly or implicitly. ???
Even though this objective is removed from the exam, object serialization and deserialization are very useful in Java remote method invokcation (RMI).
When a client passes an object to a server over the network, the object has to be serialized. When the server receives it, it has to deserialize it.