Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is "serialVersionUID"

 
Vikram Shirur
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

My Servlet Shows This Warning... "The serializable class XYZServlet_MAIN does not declare a static final serialVersionUID field of type long"....

Why Does This Happen... And How to Correct it...

What is the use of this "serialVersionUID"....

I'm Using MyEclipse WorkBench and JDK 1.4

Thanks,

Vikram Shirur,

SCJP 1.4
 
Sandeep Krish
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do a rebuild and restart of the server instance. That may resolve your problem.
 
Vikram Shirur
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it.... but Still no Change...

The Servlet is Working Correctly... No Problem...

But The warning is still there...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
serialVersionUID is used for Serializable classes.
I don't know about MyEclipse, but in the standard Eclipse, clicking on the icon which shows the warning will display a popup menu, with "Create serialVersionUID". Selecting this will add a serialVersionUID for you.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you don't care about serialization, you can still add the default ID in your class :
[code]
private static final long serialVersionUID = 1L;
[code]
[ February 21, 2007: Message edited by: Satou kurinosuke ]
 
Vikram Shirur
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes... Even in MyEclipse by clicking on the icon which shows the warning displayed a popup menu, with "Create serialVersionUID". Selecting this added a serialVersionUID for me...

Now the Warning has gone...

But Can you help me in understanding What is the Use of this "serialVersionUID"....

Thanks,

Vikram Shirur,

SCJP 1.4
 
Sandeep Krish
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can turn that eclipse warning off in Window-Preferences->Java->Compiler->Errors/Warnings->Potential programming problems.

About Serial UID:
serialVersionUID is used to ensure that someone using a newer version of your class can't deserialize an older instance or vice versa. Typically, if you change something minor in your class, like the implementation of a method, a old, saved instance of your class could be used with the new version without any problems. If you change the names of the class' fields or alter the purpose of the class, though, instances of that class that were saved under a previous version probably won't play well with the new class version. If you change something minor in your class, you can leave the serialVersionUID alone, but if you change something major, it's a good idea to change the serial version so that you or others don't get weird errors when using old instances with the new class.
 
Vikram Shirur
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks...
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic