Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SerialVersionUID

 
Mandy Bowman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there everyone, I am reading through the Monkhouse book SCJD Exam with J2SE 5 and there is one thing in it that is not fully exaplained but it is almost assumed that you know what it is. In some of their classes they use a variable:



but I don't understand exactly what this is for. What is the background knowledge that I must possess to understand this?

Mandy xxx
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable denotes the version of the current class structure.
It is to do with object serialization ( the mechanism that allows an object to be deconstructed, sent over a network and reconstructed at the other size)

The Java serialization uses serialVersionUID to determine the version of the class that is or will be serialized.

If you do not define the serialVersionUID Java will calculate one for itself based the definition of the class variables, methods and Java version you are running. This method may not produce the same version number on every occasion.

If a different serialVersionUID is calculated for the same class then
serialization will not work.

To control the version of the class you use you must implement the serialVersionUID, so it will always be the same value.

You would only ever change this number if you changed a class so that it is no longer compatible with older versions of the same class. This ensures that if a new version of a class is sent over the network and an attempt is made to reconstruct it as an instance of the older version it will fail as the serialVersionUID's will differ.

But for the purposes of the SCJD you will not be concerned with class versions so all you have to worry about is defining it, it can be any long number you like.

Mark
[ January 25, 2007: Message edited by: Mark Smyth ]
 
Mandy Bowman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark MWAH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic