File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Please explain writeObject() ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Please explain writeObject() ..." Watch "Please explain writeObject() ..." New topic

Please explain writeObject() ...

achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
I am using ObjectOutputStream and writeObject,
and I am trying to write two Strings in it.
Okay, so it compiles, but it would be nice to understand how JAVA knows where the field "model" ends and the next field "colour" starts.
I mean : if we were to use readObject(), how does the read know there are 2 fields ???

Sometimes I really like to know why JAA works in a particular way. I see it as an overly complex language.
[ November 21, 2002: Message edited by: achana chan ]

humanum errare est.
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
This is not a Servlet specific question so I am moving it to Java Intermediate.

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Pete Lyons
Ranch Hand

Joined: Aug 18, 2002
Posts: 109
The Serialization Tutorial explains some of how serialization works. If you're curious, detailed explainations of the binary format can be found on the web, or just open the file up in a text editor. Basically, you should not need to worry about the implementation details, which is why it's easy to serialize objects in some languages. Of course, the source code to ObjectOutputStream is always there for the real truth. You also might be curious about java.beans.XMLDecoder to see an alternate file format for the stored object graph.
I agree. Here's the link:
subject: Please explain writeObject() ...
It's not a secret anymore!