• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Why serialVersionUID is used in the class which implements the Serializable interface?

 
Ranch Hand
Posts: 214
Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am using Java since 4-5 years, but not getting the exact answer for the serialVersionUID in the Java class.

Why serialVersionUID is used in the class which implements the Serializable interface?

Is it compulsory to keep in the case of serialize?

Thanks in Advanced.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the best explanation is in the API docs for the Serializable interface


The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long:

 
Rd Dari
Ranch Hand
Posts: 214
Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for replying!!!
 
Maneesh Godbole
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome!

When I started learning Java, I always had the API docs open along with the code editor. I find them to be an invaluable tool while learning. I would suggest you do the same. You never know what gem of knowledge you just might discover hidden in the API docs.
 
Rd Dari
Ranch Hand
Posts: 214
Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right. Thanks for your suggestion and mostly I used to go in deep but sometimes to complete the work on time just skip so many things.

Thanks once again!
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rd Dari wrote:mostly I used to go in deep but sometimes to complete the work on time just skip so many things


Do not skip anything everything is important. Follow the guide line provided by Maneesh this will help you lot.
 
Rd Dari
Ranch Hand
Posts: 214
Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ninad Kulkarni,
Definitely I'll follow the instructions.
    Bookmark Topic Watch Topic
  • New Topic