• Post Reply Bookmark Topic Watch Topic
  • New Topic

how could java store serialVersionUID, however it is static  RSS feed

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the book OCP_ Oracle Certified Professional Java SE 8 Programmer II Study Guide, it is said that :

...static class members will also be ignored during
the serialization and deserialization process....

, there for I thought that the serialVersionUID will be ignored, however, in the same book it is said  that :

...serialVersionUID is stored with the serialized object...

which makes no sens !!!.
 
Sheriff
Posts: 23513
47
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you think about how serialization works, you can see that the version UID must be stored with the serialized data. Otherwise, how could the deserialization process tell whether the data was originally produced by the same version of the class?
 
yas sine
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yep I know, but how you can explain what static members are not stored, however, UID is stored !!!
 
Paul Clapham
Sheriff
Posts: 23513
47
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

yas sine wrote:yep I know, but how you can explain what static members are not stored, however, UID is stored !!!



I don't have to explain that, because it isn't a correct description of what happens. What happens is, the UID is stored but other static members aren't.

What requires explanation is why the books you quoted don't have a correct description.
 
yas sine
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, I see now, so you said that, it is correct that static members are ignored, except UID ??
 
Paul Clapham
Sheriff
Posts: 23513
47
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find it's better not to make assumptions about how things are implemented. However, it's true that if you serialize an object using serialVersionUID = 42 and then try to deserialize it using serialVersionUID = 86, an exception will occur. That means the deserialization process knows what serialVersionUID was at the time of serialization.

This is what you need to know about serialVersionUID.

Now, the only way I can see to implement that rule is by storing the serialVersionUID in every serialized object. But Java implementers are very smart people and for all I know they have implemented that rule in a very smart way which I didn't think of. So nitpicking about whether the serialVersionUID is actually written out is, to me, counterproductive. Whether the documentation actually says that serialVersionUID is actually stored, I don't know.
 
We don't have time for this. We've gotta save the moon! Or check this out:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!