Win a copy of Java Challengers this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Question on implementing the java.io.Serializable interface

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

Can you please help me understand something in implementing the Serializable interface in a super class.

1. When the super class implements the Serializable, then do sub-classes need to explicitly declare that they are implementing the Serializable interface?

2. Where is the use of implementing Serializable important between:

2.1 - A Data Object (Data Transfer) class - which basically holds the state.
OR
2.2 - A Helper class that has methods to say - query the DB and create instances of Data Objects to represent state.
OR
3.3 - Both of the above.
3. Is it necessary to "declare a static final serialVersionUID field of type long" when implementing Serializable. If so, what role does this value play?

 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1). You do not need - implementing and extending are transitive - it's OO concept.
3). I think that that field is optional. It is for better performance - I guess. Someone else should agree with me, because I am not sure.
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Well this thing is pretty clear using the inheritance tree. If the superclass implements serializable then the sub class will too through inheritance.

2. Serialization is usefull in 2.1. Well let me take it in terms of databases, we take dumps and transfer it, does it include the operations or does it include the values. Well serialization is basically came from restore.

3. As the point above it comes from restoration we cannot use any template for the restoration. So to specify that particular template the serialVersionUID is specified. Well its static final so it will be there in the template but not in the object. Well when the object is serialized, the object will be stamped with class's serialVersionUID. Then well you think the class was out dated and you try to update making some changes which probably changes the serialVersionUID. Then when you try to deserialize the object, surprise surprise the object won't deserialize. So now to make this happen we ourselves put the serialVersionUID in the updated class. That's about all of it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic