• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serial Version ID

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ???
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Googling found this out.It is required for serialization.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic