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 IDEs, Version Control and other tools and the fly likes Serial Version ID 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 » Engineering » IDEs, Version Control and other tools
Bookmark "Serial Version ID" Watch "Serial Version ID" New topic
Author

Serial Version ID

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
Hi,

I'm using JBoss Eclipse IDE 1.6

CODE :


at my class declation it says "The serializable class Controller does not declare a static final SerialVersionID field of type long"

What does that mean ?? what is the use/benifit of declaring serial version id ???


Jigar Naik


Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Googling found this out.It is required for serialization.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

By default, Eclipse encourages you to provide a serial UID for all serializable classes as this improves usage of serializable classes in the long run.

You can turn this warning off, or even make it an error if you like.

Moving to the IDE forum, not a servlet question.
Periakaruppan Thiagarajan
Ranch Hand

Joined: Jul 26, 2005
Posts: 65
Hi,

I have just used the same code but i am not getting any errors? Is is somthing to do with jdk version?

Thanks,
PK
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
This is not an error. It is only a suggestion to provide a UID when using a serializable class. I get it when using eclipse. The original post mentions JBoss also. Maybe you're IDE isn't generating it or you may have turned it off.
Sunil Vasudevan
Ranch Hand

Joined: Mar 05, 2007
Posts: 107
As mentioned by Anupam, it is a setting at Eclipse end as a warning when the code is compiled. If you have changed it to be flagged as an error, then Eclipse will report it as an error.

To ans your other question.. What serialVersionUID is.. Well it is a unique identifier for a class that can be serialized. All classes that can be serialized implement the marker interface java.io.Serializable. It is a mechanism using which JVM checks if the class had changed after it was serialized into a persistent medium. Example: I have UserBean class which had the following code:

------------------------------------
import java.io.Serializable;

public class UserBean implements Serializable
{
private int age = 0;

public int getAge()
{
return this.age;
}

public void setAge( int age )
{
this.age = age;
}
}
------------------------------------

serialVersionUID for the above class is 5799876628235941012L

Say you save an object of this class to a flat file.

Later you change the implementation of the class to:
------------------------------------
import java.io.Serializable;

public class UserBean implements Serializable
{
private int userAge = 0;

public int getUserAge()
{
return this.userAge;
}

public void setUserAge( int userAge )
{
this.userAge = userAge;
}
}

------------------------------------
Now the serialVersionUID for this class is -2676956332959004712L;

When you try to deserialize the older class that was persisted, JVM will now be able to know the object is now stale and no longer valid.

How we get serialVersionUID for any class?? JDK is shipped with serial version UID generator.

Type in "serialver -show" in your command prompt and provide the class name.

Hope this helps.


Sunil.V<br />SCJP2, SCWCD1.4, SCBCD1.3
 
Don't get me started about those stupid light bulbs.
 
subject: Serial Version ID
 
Similar Threads
Unable to load class for Servlet.... Need help...urgent...
Where does request goes?
Logging
Serial Version ID
My very own MVC framework...