Reputation: 811
How to determine a proper serial version ID? Should it be any big long value using some generators or any integer wld suffice ?
Upvotes: 5
Views: 4079
Reputation: 910
start command prompt
type below :
cd\
then type below
[serialver][space]-classpath[space][path of your class file][space][class file name]
e.g.
serialver -classpath C:\Users\nileshjadav\Documents\java\file_io ByteStreamDemo
please do not add extension like ByteStreamDemo.java or ByteStreamDemo.class simply used just ByteStreamDemo
Upvotes: 1
Reputation: 583
Adding to the answer few things to take care before generating serialVersionUID using java serialver utility.
JDK path till bin to be set in environment variables. Other wise you may get "'serialver' is not recognized as an internal or external command".
Add class path where your class file is located or go to the directory where your class file is there.
run serialver .. This will give you SerialID.
Class name pass to this utility does not include .class extension.
Upvotes: -1
Reputation: 68268
Possible uses:
200906121213
when the class changes in an incompatible way.Upvotes: 2
Reputation: 160954
Frankly, as long as the serialVersionUID
differs between the different versions of your class, that's all that matters.
What would be bad is if there are two versions of the same class with differing serializable fields having the same serialVersionUID
-- that's probably going to cause a problem when performing serialization.
Additionally, if the changes to the class will not affect serialization (e.g. serializable fields in the class remain the same), then the serialVersionUID
can remain the same.
IDEs like Eclipse will automatically generate an ID for classes which implement Serializable
based on the fields and other information regarding the class, so that may be the easiest route to take to generate an unique ID.
For further reading on the topic, the Discover the secrets of the Java Serialization API would be a good read. There is a section called "Version Control" which discusses the serialVersionUID
issue.
Upvotes: 4
Reputation: 8756
The serialver tool comes with Sun's Java Development Kit (JDK). It takes a full class name on the command line and returns the serial version ID for that compiled class, or can be run with the "-show" parameter to launch a small interactive GUI.
So if your class is Foo, run
serialver Foo
and you'll get some sort of output like this:
Foo: static final long serialVersionUID = -6618469841127325812L;
Take the code starting with "static" and place it inside your class with other static variables. Now the serial version ID is locked in the class.
Upvotes: 2