wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes serialVersionUID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "serialVersionUID" Watch "serialVersionUID" New topic
Author

serialVersionUID

James Clarke
Ranch Hand

Joined: Oct 04, 2004
Posts: 148
Hi Ranchers,

I was generating serialVersionUID for some of my classes(using serialver), which even though are not implementing Serializable are extending other classes which are Serializable.

I get the UID to be 5165L for two completely different classes, which doesnt make sense, as I believe the UID is generated based on method and variable names in the class.

Can anyone shed some light on this?

thanks in advance,
J.C
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Originally posted by James Clarke:
I was generating serialVersionUID for some of my classes(using serialver), which even though are not implementing Serializable are extending other classes which are Serializable.

Hi,

as far as I know, serialVersionUID is only used for Serialization.


I get the UID to be 5165L for two completely different classes, which doesnt make sense, as I believe the UID is generated based on method and variable names in the class.

2 classes can have the same UID, the check is only on a "per class" basis.

You are mixing 2 things here: "manual" and "default" UID.
When you manually set the UID, that's what the UID is. The UID must match when serializing.
When you don't set it manually, a default value is define every time the class is modified.

That's the key point, by default your modified classes will never be compatible because the UID keep changing. When managing it manually, you decide when the changes impact the serialization.

* In so many words, serialVersionUID is used to apply versions on your classes and prevent the Serialization from proceeding in case of incompatibility (which could mess with your data??).

I suggest you read this: http://mindprod.com/jgloss/serialization.html#SERIALVERSIONUID

I personally use the current date as UID: 20080405L

bye,
Alex
[ April 05, 2008: Message edited by: Alex Belisle Turcot ]
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
In the following article you can find out how the serialVersionUID is generated by the serialVer tool.

Stream Unique Identifiers

If you really want to delve into it, then you can do some tests and see how it turns out.
[ April 10, 2008: Message edited by: Edwin Dalorzo ]
 
Don't get me started about those stupid light bulbs.
 
subject: serialVersionUID
 
Similar Threads
Deserialisation when unique ID has changed
Can enum define its serialVersionUID or it has by default?
What is "serialVersionUID"
serializable
few Qs on serialVersionUID