• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need clarity on a basic question about Serialization

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As we all know that everything in computers is stored in the form of bits and bytes(eventually). So how does this concept of Serialization works, as even if we have normal objects they are in the form of bits and bytes; when we send it from one PC to another PC, it will be sent in the form of bytes and in the other PC, it gets converted as a picture or document or XLS or any other message. So in fact all the java objects that we have are basically represented in bytes. So what is the definition of Serialization of "flattening the objects into bytes and inflating it on the other end as objects"


I have tried Sun API , but coulnt get much info. .Looking for some clear answers from the folks of javaranch
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Serialization creates a file that the JVM can use to reconstitute data into Objects.

So, effectively, you serialize your objects (which creates the file), then you can bring that file to a new computer and run your program to de-serialize your objects.

There is no magic. The data comes out of the file. If you want to see what kinds of data gets stored, you can create a serializable class, make some instances and serialize them. Then close out of the JVM and browse the file.
 
Ajeeth Kumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Janeice DelVecchio wrote:Serialization creates a file that the JVM can use to reconstitute data into Objects.

So, effectively, you serialize your objects (which creates the file), then you can bring that file to a new computer and run your program to de-serialize your objects.

There is no magic. The data comes out of the file. If you want to see what kinds of data gets stored, you can create a serializable class, make some instances and serialize them. Then close out of the JVM and browse the file.



Thanks for the reply Janeice. {My apologies for not being able to catch up on this topic sooner }

So can we say that serialization provides a "container" for a java object, just like how jpg files are for images or pic?

Also, when you say where can we browse the serialized files, where/how can we see them?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ajeeth Kumar wrote:So can we say that serialization provides a "container" for a java object, just like how jpg files are for images or pic?


You could say that, yes. Other people might not consider a JPEG file to be a container for a picture, however, but it's true that serializing a Java object provides a representation of that object which can be transported elsewhere and converted back into another object, so in that sense it's the same sort of thing.

Also, when you say where can we browse the serialized files, where/how can we see them?


If you wrote the serialized object to a file, then you can see the file using any software which allows you to see files. As far as the operating system is concerned it's just another file, and the O/S doesn't care whether it contains a serialized Java object or a JPEG version of a picture or a text file containing your credit-card number or anything else.

But if you look inside the file, don't expect to be able to visualize the Java object, any more than you can visualize a picture by looking at the bytes in a JPEG version of the picture.
 
Ranch Hand
Posts: 384
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
basically what serialization does is to gather the values of the objects that you serialize and write them to a file ... now the magic begins (i would say magic, yes magic) because you do not need to pass the objects ( all the objects that you serialize) but just this file ...

and as you know that classes can have mammoth number of objects (mammoth < yourComputersMemoryLimit) these flattened or written to file values are then used to populate another same class objects ...

and thats it ... you are done ...

happy coding ...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic