File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes About serialVersionUID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About serialVersionUID" Watch "About serialVersionUID" New topic

About serialVersionUID

Tanzy Akhtar
Ranch Hand

Joined: Jul 19, 2009
Posts: 110

Can somebody explain what is serialVersionUID and when to define in the class?

I saw such a class having serialVersionUID defined more than once and with the same name and value like

What's the need of this?


Roll with punchers, there is always tomorrow.
Techie Blog --
manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
Just google it, and you will get what it is used for. In short, it is used in serialization by JVM.

I was wondering how come you can have serialVersionUID defined more than once. In fact you can not have any variable definition more than once at the same level (class/local).

love your job and not your company;
...because you never know when your company will stop loving you!
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
The idea of the SUIDis that when you have two instances of the same class with the same SUID, the JVM assumes they are from the same class object. If you have different SUIDs, the JVM may assume they are from different versions of the class, and the objects may not be de-serialized.
And I agree it is very peculiar to have two definitions in the same class.
I agree. Here's the link:
subject: About serialVersionUID
It's not a secret anymore!