aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialization JSCP 6.0 (manually invoking writeObject() ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serialization JSCP 6.0 (manually invoking writeObject() )" Watch "Serialization JSCP 6.0 (manually invoking writeObject() )" New topic
Author

Serialization JSCP 6.0 (manually invoking writeObject() )

Rafi Fareen
Ranch Hand

Joined: Aug 28, 2009
Posts: 75
hey guys,

i have been reading this scjp 6.0 book, there is some explanation about how to serialize an object having relationship with another class's object which is not serializable ... below is the code, when i execute it i'm getting two exception (Java.io.IOException: readError & java.io.IOException writeError) the main aim of this code is to test serialization not proper code writing or following any standards.



regards,

Rafi (planning to appear for scjp 6.0 soon)
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9319
    
  17

Serialization is not a part of SCJP 6 any more, so you don't have to worry about it now. Also please indent your code in the future. Now you can't close the input and output stream in the readObject and writeObject methods respectively. So remove the oos.close and ois.close method calls. Also in the readObject method you didn't assign the Collar object to theCollar field of the class...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rafi Fareen
Ranch Hand

Joined: Aug 28, 2009
Posts: 75
Ankit Garg wrote:Serialization is not a part of SCJP 6 any more, so you don't have to worry about it now. Also please indent your code in the future. Now you can't close the input and output stream in the readObject and writeObject methods respectively. So remove the oos.close and ois.close method calls. Also in the readObject method you didn't assign the Collar object to theCollar field of the class...


oh sorry for that collar object .... the main problem is with writeObject method .....

as well how can i get the updated objectives for scjp 6.0 (i'm reading scjp 6.0 book by bert bates & sierra, according to the book serialization is part of the exam scjp 6.0 ) please let me know where i can access the exact objectives as i'm appearing for the exam soon.

regards,

Rafi
Rafi Fareen
Ranch Hand

Joined: Aug 28, 2009
Posts: 75
Ankit Garg wrote:Serialization is not a part of SCJP 6 any more, so you don't have to worry about it now. Also please indent your code in the future. Now you can't close the input and output stream in the readObject and writeObject methods respectively. So remove the oos.close and ois.close method calls. Also in the readObject method you didn't assign the Collar object to theCollar field of the class...


wait, its working now.

i have removed the ObjectOutputStream.close() & ObjectInputStream.close() from both the methods and the main class and it started working ??? isn't it weired.

i mean i should get a warning for using close() method, why was i getting exceptions???


hey Ankit any personal advise for the exam (i mean looking at your score, 98%, wow, you should be expert ....) give me some useful advises (i'm weak in assignments chapter).

regards,

Rafi
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9319
    
  17

Rafi Fareen wrote:how can i get the updated objectives for scjp 6.0

The updated objectives are available here.
i have removed the ObjectOutputStream.close() & ObjectInputStream.close() from both the methods and the main class and it started working ?

Isn't that what I said??
i should get a warning for using close() method, why was i getting exceptions?

What type of warning?? The call is perfectly legal java code, so you won't get any warning. The writeObject and readObject methods we create are called by the serialization mechanism to give us control over the process, but after our code is done executing, there is some additional processing that is needed to serialize (or deserialize) the object. That's why you can't close the input/output stream. If you see the source code of ObjectOutputStream, in the writeSerialData method, there is a line of code
this line invokes our writeObject method, and after that some additional work is done by the ObjectOutputStream class, that's why closing the stream results in an exception...
Rafi Fareen
Ranch Hand

Joined: Aug 28, 2009
Posts: 75
What type of warning?? The call is perfectly legal java code, so you won't get any warning. The writeObject and readObject methods we create are called by the serialization mechanism to give us control over the process, but after our code is done executing, there is some additional processing that is needed to serialize (or deserialize) the object. That's why you can't close the input/output stream. If you see the source code of ObjectOutputStream, in the writeSerialData method, there is a line of code
this line invokes our writeObject method, and after that some additional work is done by the ObjectOutputStream class, that's why closing the stream results in an exception...


looks like i understood your point exactly .... thanks bro
Muthi ur Rahman Mohammed
Greenhorn

Joined: Mar 13, 2010
Posts: 2
Hi,

I am Muthi. I was learning Serialization today and during the process came across this forum. I follwed the program and code. I have one question regaring the program. In the program collar size is set to 6 and dog size is set to 7 and serialization is done following the creation of dog object. The programmer is then changing the values of collar and dog sizes and follwing which deserialization is done. When output is printed, value of collar zize is 99 and dog size is 23 but the serialized object values were 6 and 7. How is this happening?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serialization JSCP 6.0 (manually invoking writeObject() )