aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Does deserializing an object in another JVM call the static initializer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Does deserializing an object in another JVM call the static initializer?" Watch "Does deserializing an object in another JVM call the static initializer?" New topic
Author

Does deserializing an object in another JVM call the static initializer?

Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

Hi everybody,

Does deserializing an object in another JVM call the static initializer?
It does not within the same JVM as the class is already loaded while serializing it, however what about in another jvm? Would the static initializer get called?

Thanks in advance.



OCAJP 7, OCPJP 7
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Objects don't have static initializers. Classes have static initializers. And those static initializers are called when the class is loaded.

And there's no reason why a JVM, when deciding whether to load a class, would pay any attention to any other JVMs which happen to be running elsewhere. If it needs the class then it's going to load the class.

As you can see this has very little to do with serialization of objects.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Does deserializing an object in another JVM call the static initializer?