aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes private(?) writeObject/readObject 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 "private(?) writeObject/readObject" Watch "private(?) writeObject/readObject" New topic
Author

private(?) writeObject/readObject

Roely de Vries
Greenhorn

Joined: Jan 06, 2007
Posts: 1
Question about writeObject and readObject,


In this code fragment b cannot be serialized,therefore it is marked as transient in A.

A is serialized an deserialized by TestSer. Because A has the private methods writeObject and readObject instead of os.defaultWriteObject and ois.defaultWriteObject.

The question is, how is this possible?
writeObject and readObject are private methods of A, so how can they be invoked by the serialization proces?


(edited: added tags)
[ January 30, 2007: Message edited by: Barry Gaunt ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18829
    
  40

The question is, how is this possible?
writeObject and readObject are private methods of A, so how can they be invoked by the serialization proces?


Other questions that you may also ask include:

- How does the defaultReadObject() method of the stream object access the private instance variables?

- How come the readObject() method doesn't call the super.readObject() method? Don't the parent class have special serialization needs too?

- How come all readObject() and writeObject() methods are private?

Serialization is one area where the "basic rules of Java" does not apply. You need to learn it independently -- without thinking in java.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: private(?) writeObject/readObject