This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialization......... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serialization........." Watch "Serialization........." New topic
Author

Serialization.........

Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
readObject() and writeObject() methods are used for normal serialization and deserialization process...


defaultReadObject() and defaultWriteObject() methods are used to save the state of the object manually....


am i right?


SCJP5 and SCWCD1.5
Think Twice Act Wise...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

I think you got it wrong.

readObject and writeObject are used to serialize objects automatically.

If you want to manipulate the serialization process (like you would like to serialize a transient field), then you can override these methods. Then when an object of the class is serialized or deserialized, these methods are called by the JVM. If you want the automatic serialization to happen and then want to do some extra work during serialization, then you can call defaultReadObject and defaultWriteObject

eg
if you want your object to be written automatically, and add a line with "bye" at the end, then you will

override writeObject
call defaultWriteObject in the overriding method
manually write "bye" to the output stream...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Serialization.........