• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Serialization

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain to me what happens when you are calling say a.writeObject(ref) as far as what FileOutputStream and ObjectOutputStream are doing with the class code to make it possible to be deserialized? With a being a reference variable to a FileOutputStream, and ref is an object of a class.

Is it saving like bit patterns or....?
 
Bartender
Posts: 15737
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume you mean "a" holds a reference to an ObjectOutputStream, not a FileOutputStream. I also assume you mean serialize, because writeObject serializes an object, not deserializes.

ObjectOutputStream uses reflective code to save the class of an object, and then all its fields. It just reads all the fields and stores them in some sort of format. If you have specific questions, you could look at the source code for ObjectOutputStream.
 
Scotty Mitchell
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I meant to say or was trying to imply is what does writeObject do to the class code to allow for deserializing later by an ObjectInputStream. And yes you are right "a" should be a reference to a ObjectOutputStream object. Sorry for the confusion.

What do you mean by reflective code?

Good idea to look at the source code...a lot is going on behind the scenes that you never really know about until you look at the source code.

thanks~
 
Stephan van Hulst
Bartender
Posts: 15737
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reflective refers to the reflection API. They are a collection of classes that allow you to inspect Java code. Take a look at the package java.lang.reflect.*.
 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

all non transient and non static fields are saved during serialization in a specific binary format, I think it also saves object graph , you could probably explore that part.
 
Paper beats rock. Scissors beats tiny ad.
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic