This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Learn Java with Math: Using Fun Projects and Games and have Ron Dai on-line!
See this thread for details.
Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java 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
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

private(?) writeObject/readObject

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question about writeObject and readObject,


In this code fragment b cannot be serialized,therefore it is marked as transient in A.

A is serialized an deserialized by TestSer. Because A has the private methods writeObject and readObject instead of os.defaultWriteObject and ois.defaultWriteObject.

The question is, how is this possible?
writeObject and readObject are private methods of A, so how can they be invoked by the serialization proces?


(edited: added tags)
[ January 30, 2007: Message edited by: Barry Gaunt ]
 
author
Posts: 23844
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The question is, how is this possible?
writeObject and readObject are private methods of A, so how can they be invoked by the serialization proces?



Other questions that you may also ask include:

- How does the defaultReadObject() method of the stream object access the private instance variables?

- How come the readObject() method doesn't call the super.readObject() method? Don't the parent class have special serialization needs too?

- How come all readObject() and writeObject() methods are private?

Serialization is one area where the "basic rules of Java" does not apply. You need to learn it independently -- without thinking in java.

Henry
 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!