This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Serialization need help

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have a question with Serialization.
There are two special private methods that allow us to de/serialize the variable of an object (writeObject() and readObject()).
We can use writeInt() method to save an int type variable.
But, how about if we want to save more that one int type variables and then we want to deserialize them again?
Then, since those methods are private but special, will it be inherited by the subclass?

For example, I found this at page 451 SCJP 5 Sierra Kathy's book.

Thank you!!

Sorry for my bad English
[ August 06, 2007: Message edited by: fedry kemilau ]
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by fedry kemilau:
We can use writeInt() method to save an int type variable.
But, how about if we want to save more that one int type variables and then we want to deserialize them again?

Use as many writes and reads as you need.

Then, since those methods are private but special, will it be inherited by the subclass?

Since they are private, they are not inherited by subclasses. But the serialization framework ensures that they are called in the correct sequence.


[EDIT] Make the sample compilable with 1.4.
[ August 07, 2007: Message edited by: Manfred Klug ]
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats a good example Manfred.

The output is as follows:


A.writeObject
B.writeObject

44 55 66
A.readObject
B.readObject

44 55 66



The lines in bold shows that they are NOT inherited and indeed of the respective classes.

A small suggestion when giving the programs.

Actually in the main method the String array arguments is "String...". . It would be better if you can just give the correct and working program as "String[]". I understand that the reader whoever is in need can correct it. But would it take more time for a person who had typed such a long program anyways?
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Raghavan Muthu:
Actually in the main method the String array arguments is "String...". It would be better if you can just give the correct and working program as "String[]". I understand that the reader whoever is in need can correct it. But would it take more time for a person who had typed such a long program anyways?

That is the problem if you only use one version of the compiler. You will fast forget the differences to other versions. I will change the sample to make it work with 1.4.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


That is the problem if you only use one version of the compiler. You will fast forget the differences to other versions. I will change the sample to make it work with 1.4.



Terribly sorry manfred. I still use 1.4 only.
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Raghavan Muthu:
Terribly sorry manfred. I still use 1.4 only.

No problem. You are right, the sample is useful for 1.4 people too.
 
I'm so happy! And I wish to make this tiny ad happy too:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic