File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why static variable serialized here?

 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



This is a book example. Chapter:6, example:15, page:519.

Answers are:
(1) 10 0 10
(2) In order to alter the standard deserialization process you would implement the readObject() method in SpecialSerial.


I am not getting why serialised allows static variable? Also I am not getting what (2) answer wants to say.
 
Priyam Srivastava
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static variables are not meant for serialization. but it if legal to have static variables in the class whose object you want to serialize.
here the static variable z doesn't get serialized..
[ July 12, 2007: Message edited by: Priyam Srivastava ]
 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In code "z" is a static variable & it gets change after serialized.
 
Priyam Srivastava
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to deserialize the object in any other file(try to write the deserialization process in file say Deserialize.java)...then observe whether the value of z changes or not.

by the way what value of z you expect??
 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it. But can you explain second answer?
 
Priyam Srivastava
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it would be better if you go through Serialization topic once again from book K&B. you would understand better with example..
 
Jared Folino
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be a bit clearer as well if you remember that s.z is shortcut syntax. The full statement would be SpecialSerial.z
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic