SCJP 6. Learning more now.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:You need to serialize the Dog object first, then de-serialize it again. This means using an ObjectOutputStream and ObjectInputStream, using either a file (FileOutputStream and FileInputStream) or memory (ByteArrayOutputStream and ByteArrayInputStream) as backing streams:
SCJP 6. Learning more now.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:Strange. I tried your code with my code in the middle* and it ran successfully. Then again, I didn't use try-catch but declared the main method to throw Exception (just to be lazy).
Can you show us the code you added? I think the problem is in there somewhere.
SCJP 6. Learning more now.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Notice that both methods are (and must be) declared private, proving that neither method is inherited and overridden or overloaded. The trick here is that the virtual machine will automatically check to see if either method is declared during the corresponding method call. The virtual machine can call private methods of your class whenever it wants but no other objects can. Thus, the integrity of the class is maintained and the serialization protocol can continue to work as normal. The serialization protocol is always used the same way, by calling either ObjectOutputStream.writeObject() or ObjectInputStream.readObject(). So, even though those specialized private methods are provided, the object serialization works the same way as far as any calling object is concerned.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:You need to serialize the Dog object first, then de-serialize it again. This means using an ObjectOutputStream and ObjectInputStream, using either a file (FileOutputStream and FileInputStream) or memory (ByteArrayOutputStream and ByteArrayInputStream) as backing streams:
SCJP 6. Learning more now.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:.....
SCJP 6. Learning more now.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions