• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Serialization need help

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic