• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

what is the use of Serialization in java?

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the use of Serialization in java? In what situation should we use serialization?
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to save the state of objects so you can pick up on them later, Serialization is a perfect candidate.
 
lowercase baba
Posts: 13018
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
serialization can be used to save an object from one JVM and load it into another. For example, you can serialize it, shut down your jvm/computer, come back a week later, deserialize it, and you have the object in the same state.
 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please tell me the situations/scenarios when we need to serialize an object
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Serialization is also helpful when you want to transmit your objects over the network. e.g. RMI
More detailed information can be found here
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that serialization is well-suited for temporarily storing objects, or for transferring objects over a network, but it is not very good for long-term storage. The problem is that there is a tight coupling between your classes and the serialized objects. If you change something in your class (you add or rename a member variable, for example), then you will not be able to deserialize objects from old files with the new version of the class.

Suppose that you wrote a program which saves data by serializing objects in a file. Clients start to use the program. Someday you create a newer version of the program, in which you changed the classes that hold the data. Clients will not be able to read their saved files with the newer version, because the old serialized files have become incompatible because you changed the classes. So, if you write such a program, don't use serialization; use a well-defined (preferrably standard) file format instead.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic