This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes What is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "What is "serialVersionUID"" Watch "What is "serialVersionUID"" New topic
Author

What is "serialVersionUID"

Vikram Shirur
Ranch Hand

Joined: Jul 27, 2006
Posts: 33
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

Joined: Jan 02, 2007
Posts: 58
Do a rebuild and restart of the server instance. That may resolve your problem.
Vikram Shirur
Ranch Hand

Joined: Jul 27, 2006
Posts: 33
I tried it.... but Still no Change...

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

But The warning is still there...
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Jul 27, 2006
Posts: 33
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

Joined: Jan 02, 2007
Posts: 58
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

Joined: Jul 27, 2006
Posts: 33
Thanks...
 
Don't get me started about those stupid light bulbs.
 
subject: What is "serialVersionUID"
 
Similar Threads
Deserialization problem - InvalidClass w/ negative serialVersionUid for local class
Regarding Stream Versioning
Compiler Warning when you implement Serializable interface
generate serialVersionUID in netbean 5.0
serializable