• Post Reply Bookmark Topic Watch Topic
  • New Topic

file Serialization  RSS feed

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serial data is sent one element at a time, like a line of cars on an
assembly line


I read this in Java in 21 days book.But can't understand this.May you explain?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
serial just means you have one pipe, and everything goes through it one at a time. you send the first bit, then the second, then the third, etc.

parallel means you have multiple pipes, so you can send more than one thing at a time. if you had 8 pipes, you could send each of the bits from a byte all at the same time, and the receiving end could re-assemble them.

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

That "line of cars on an assembly line" seems like a silly analogy to me.

Henry
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I can say:

Stream consist of serial bytes, In serialization, an object became serial of bytes in stream. That's why it called serialization.

Right?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone comfirm?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File OurpurStreams write bytes to a file. ObjectOurputStreams turn
objects into data that can be written to a stream.
So we make a FileOutputStream that lets
us write to a file, and we hook an ObjectOutputStrearn (a chain stream) on the end of it.


Can I say ObjectOutputStrearn is like a filter for FileOutputStream , so then stream write object?
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A question:

At first, Does ObjectOurputStream serialize the object, then the object write on FileOutputStream?
Or Does FileOutputStream creates a stream, Then it's filtered by ObjectOurputStream?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think good 00. Each class
does onething well. File OurpurStreams write bytes to a file. ObjectOurputStreams turn
objects into data that can be written to a stream. So we make a FileOutputStream that lets
us write to a file, and we hook an ObjectOutputStrearn (a chain stream) on the end of it.
From �Head hhhhehehh
head first java

It is not still clear, Which one first?
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:
Think good 00. Each class
does onething well. File OurpurStreams write bytes to a file. ObjectOurputStreams turn
objects into data that can be written to a stream. So we make a FileOutputStream that lets
us write to a file, and we hook an ObjectOutputStrearn (a chain stream) on the end of it.
From �Head hhhhehehh
head first java

It is not still clear, Which one first?


You use FileOutputStream to write to a file. But for that you would need some data to be written to file. So for that you use ObjectOutputStream that uses the objects to create the data. First you would require an ObjectOutputStream, but to that you need to specify which file the data has to be store- so you also need a FileOutputStream. You are delegating the writing to a file to the FileOutputStream and ObjectOutputStream is concerned with creating the data to be written.

Internally ObjectOutputStream has a private class(and it extends OutputStream) which uses this OutputStream (FileOutputStream) passed in the constructor of ObjectOutputStream.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate Mohammad

But there is question for



In this code data transfers without usage of object outputstream or dataoutputstream or....

But you told:

You use FileOutputStream to write to a file. But for that you would need some data to be written to file. So for that you use ObjectOutputStream that uses the objects to create the data.
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use ObjectOutputStream in case of Serialization. And for that you want the data in your objects to be written to the file. In otherwise usual cases you can manually write the data in the objects using FileOutputStream. Consider cases where the objects contain other objects and then that contain other objects- in this case you cannot keep obtaining the data from each instance and then write it to the file. You would need a simpler mechanism and that's where Serialization is used.

And in your example above its a simple case of writing some data to a file. And ObjectOutputStream doesn't come into picture here.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then ObjectOutputStream is like a person, that gets on a bus to go NW.and Bus is FileOutputStream here,

Or FileOutputStream is like a rail, and ObjectOutputStream is like a diesel wagon.

ObjectOutputStream gets on FileOutputStream and goes to destination.

Good example?
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote: . . . Good example?
No
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohh.... I guess I understand it...May you tell me what is problem about my example?Thanks!
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The streams do not take each other anywhere. They send data across themselves, altering the format of those data for their respective destinations.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!