Win a copy of Head First Android this week in the Android forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

serialVersionUID ??

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is serialVersionUID field? Why it is required?. Where it is used? Is it required for all classes?
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The serialversionUID field holds a unique number that identifies the class' current development. The idea is to maintain a field that can be used to check where a serialized object is based on the same class that the current VM has loaded.
It's not a required field, but it can be very helpful. It's only usable for classes that implement Serializable.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suren,
The serialVersionUID allows you to explicitly specify the value of something called a stream unique identifier (SUID) that's normally calculated by Java's serialization mechanism. You're never required to define the serialVersionUID field, but you may find it useful sometimes. The SUID value (either one you explicitly define or one that's calculated at run time) of a class is included with the stream of bytes that's written when you serialize / marshall an instance of that class. Then, when that byte stream is being deserialized / unmarshalled, the SUID value in the byte stream is compared with the one for the local class definition to make sure that the two are identical and therefore, compatible.
I can't provide you with more information on how and when to use serialVersionUID without writing a very long response. However, if I haven't fully answered your questions (or even if I have ), I'd encourage you to consider picking up a copy of my book. It includes a chapter on data persistence where I discuss serialization in general and SUIDs in particular in much greater detail.
------------------
Brett Spell
Author, Professional Java Programming
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
since GenericServlet implements Serializable and most people agree that it is a good practice to declare serialVersionUID for classes that implements Serializable, would it also be a good practice to hardcode serialVersionUID in a servlet?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic