• 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

few Qs on serialVersionUID

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranches,

I am working on URLyBird. Using RMI. Can anybody clarify following doubts regarding generating serialVersionUid?
1. Is it mandatory to declare own serialVersionUid? or can we leave this job to compiler?
2. Can 2 serializable classes can have same serialVersionUID?
3. These IDs make sense only for objects which are transported over network right? (like only Remote objects..)

i couldn't find much info regd this in this forum. so starting a fresh topic. pl help.

Thanks in advance.
Naveen
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Naveen,

A lot of information about serialVersionUID can be found here. After reading this article you should be able to answer your own questions.

The serialVersionUID is a universal version identifier for a Serializable class. Deserialization uses this number to ensure that a loaded class corresponds exactly to a serialized object. If no match is found, then an InvalidClassException is thrown.


1. I would declare it myself.
2. of course (all my classes in my assignment had the same serialVersionUID: 1979, my year of birth)
3. Every class that implements Serializable interface should declare a serialVersionUID.

Kind regards,
Roel
 
Naveen Hegde
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roel,
Thanks a lot for your quick reply.
Yes. Things are much clear now. I too prefer to follow your technique.
But one need to know when to change the serialversionUid (as defined in specs). This makes it mandatory for junior programmers to understand the importance of this value whenever making changes to the class .
 
Ranch Hand
Posts: 497
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using this thread....
Anybody know if somebody lost points by only implements serialiVersionUID field in classes that will be transfer by network ? and let anothers without !
Regard
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Grande Fernando!

Anybody know if somebody lost points by only implements serialiVersionUID field in classes that will be transfer by network ?



Well, if the class is going to be transfered by network, then it must implement java.io.Serializable, and that's the only case you need the serialVersionUID. If you don't explicitly create one, then the compiler will create one for you. This is related to the version of the class. Whenever I create a class that implements Serializable, I always declare this field.
 
Fernando Franzini
Ranch Hand
Posts: 497
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi brow Roberto
Would you mind to tell me wich classes were in your assignment ?
(by the way, sunday we have a soccer meet....sp x timão lolllll)
Regards.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fernando,

Also extending from JFrame or Exception for example will lead to defining a serialVersionUID. And like I said before: if my IDE told me to define a serialVersionUID, I did.

I have 2 classes which implement Serializable, just my transfer objects which are transferred (hence the name) across the network.

Kind regards,
Roel
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use the -Xlint:serial when compiling your source code, then it will tell you which classes needs or inherit serialVersionUID. Most Swing subclasses, serializable classes and exception classes need one.

I declared my own serialVersionUID.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

... extending from JFrame ... will lead to [a requirement for] defining a serialVersionUID.


I would question whether anyone needs to extend from JFrame for this assignment. Are you truly creating a new class that is a JFrame to be used by other classes, or would it be more true to say that your GUI has a JFrame?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew,

You are correct: the "has a" relationship is more appropriate in this assignment than an "is a" relationship.

And as a small note/remark: the ServerWindow in Denny's DVD is also extending JFrame

Kind regards,
Roel
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I knew somebody would call me out on that.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic