java - Are static variables serialized in Serialization process -


i'm stumbled upon understanding java serialization. have read in many documents , books static , transient variables cannot serialized in java. declare serialversionuid follows.

private static final long serialversionuid = 1l; 

if static variable not serialized then, face exception during de-serialization process.

java.io.invalidclassexception 

in serialversionuid deserialized object extracted , compared serialversionuid of loaded class.

to knowledge think if static variables cannot serialized. there no point of exception. may wrong because i'm still learning.

is myth "static , transient variables in java cannot serialized". please correct me, i'm in mess concept.

serialversionuid special static variable used serialization , deserialization process, verify local class compatible class used serialize object. it's not static variable others, not serialized.

when object of class serialized, class name , serial version uid written stream of bytes. when it's deserialized, jvm checks if serial version uid read stream of bytes same 1 of local class. if they're not, doesn't try deserialize object, because knows classes incompatible.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

java - stack overflow exception on xml transformation -