• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

serialVersionUID in java

 
Ranch Hand
Posts: 113
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was reading an article today and it said it is important to give serialVersionUID variable to your class which we think will be required to serialize. My question are given below
1.) what will be the problem we will face if we do not give serialVersionUID in our serialized java class (i know java will create one for us if we dont give but what is the actual significance)
2.) I got to know that serialVersionUID should be unique in our class and there is a serialVer utility from java which create a unique number for every class. now my question is i give every serialized class the same serialVersionUID, what problems we will face during serialization and de-serialization process.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
serialVersionUID is used by Java Serialization mechanism to detect if the target object was modified during serialization/deserialization process. If you will try to cast deserialized object to it's original type and JVM will see, that serialVersionUID differs in class definition and in inctance variable of an object, it will cast InvalidClassExceptions.
The problem with autogenerated serialVersionUID is that it is being generated on the base of some iformation about the class that JVM has and may differ from one version of JVM to another, so you can have collisions serializing your objects on one system and trying to deserialize them on other.
 
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even you get warning from compiler if you don't have serialVersionUID in a class implementing the Serializable interface.
 
Sheriff
Posts: 22702
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not necessarily. I've never had that warning when compiling from the command line. In Eclipse I do get that warning, but you can turn it off if you want. I believe the default is off, but I can't remember.
 
Do Re Mi Fa So La Tiny Ad
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic