Possible Duplicate:
Why should I bother about serialVersionUID?
I am going through some exception handling code and i saw something named as serialVersionUID. What this uid is for?? Is it only limited to exception or can be used in all classes??? what is the advantage of this id???
serialVersionUID
is a field to define the version of a particular class while seriializing
& deseriializing
.. consider a scenario where you have a class Employee
which has 3 fields which has been in production for some time (meaning there may exist many serialized versions of employee objects), when you update the class to include (say a 4th field) then all the previous class (which are serialized) cannot be casted or de-serialized to the new one & you'll get an exception.
to avoid this issue, you can use the serialVersionUID
field to tell JVM
that the new class is in fact of a different version (by changing the serialVersionUID
).
@Farmor
& @Tom Jefferys
said pretty much the same thing, but with an example things look a lot simpler.