aspose file tools
The moose likes Beginning Java and the fly likes Why Serialization? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Why Serialization?" Watch "Why Serialization?" New topic
Author

Why Serialization?

sirisha makkapati
Ranch Hand

Joined: Dec 10, 2006
Posts: 83
Serialization means Writing State of an Object in to Byte Stream.In Which situation we have to write an object in to byte stream
Any one can tell me exact answer.
Thanks..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular please see:
Carefully Choose One Forum/

This forum is reserved for servlet questions.

Again, welcome to JavaRanch and good luck with your question.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Well, there could be several reasons.

One reason very well known is RMI (Remote Method Invocation). With this technology it is possible that two separate JVM (Java Virtual Machine) transfer objects between each other.

In order to achieve this, many objects are serialized and transfered through the wire back and forth between the the two JVMs.

You could use serialization also to save the state of an application, so that when the application restarts you can recover to the particular moment when the application was closed.

And I am pretty sure many other could suggest dozens of other uses for serialization.
[ December 21, 2006: Message edited by: Edwin Dalorzo ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Think of serialization any time you want to send an object over some path that isn't a real method call. As mentioned before you can send that byte stream to another computer over the network whether RMI, raw sockets or JMS, write it to a file or a database, or whatever you need.

Java's "serialize" operation generates a special Java format, but we use the word "serialize" to talk about converting your object to and from XML or CSV or delimited strings or any other format.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Md. Mohd
Greenhorn

Joined: Apr 11, 2006
Posts: 12
The real use of serialization is whenver you are transfering some data on the n/w. Lets say that there is an application that works with Mobile and server . The mobile phone acts as the client for such application. Now in this case if the mobile/user request some data from the server on the device , then the data that is sent from the server must be in the exact order as it was on the server . Thus to achieve this goal serialization is required.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"HereToLearn",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted, often without warning

thanks,
Dave
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

Sending an ojbect across a network connection is one. This is used often in application server clustering.

Of course, writing to the file system is the most obvious. This can also be helpful when testing JSP pages with complex navigational structures.

-Cameron McKenzie


Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
Adhir Gupte
Greenhorn

Joined: Dec 28, 2006
Posts: 3
Hi,

Serialization is a very important concept. This proves a bliss in java when we are transferring data over network. Object serialization helps us when we need to transfer a file to a remote location. A serialize object is converted to a Byte Stream say a ByteArray[] then the recieving end converts the byte array to an object by deserializing the same.

adhir.
Chris Ringer
Greenhorn

Joined: Dec 04, 2006
Posts: 7
So, just curious, what happens if an object (MyNeatClass version 1.0) is serialized and then before deserialized, someone installs a newer version of the class (MyNeatClass version 1.1) on the system? How does deserialization handle that? Thanks.

Chris
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Well, Chris, what happens may depend on several things.

You should read the Object Serialization Specification to understand better how the process works.

Look into the use of SerialVersionUID and specially pay attention to the Versioning of Serializable Objects chapter.
Guru dhaasan
Ranch Hand

Joined: Sep 13, 2006
Posts: 126

think of this. you wrote a simple gaming program and when the user tries to close it, the user wants to start next time where he left off. These kind of things you can achieve using serialization


Thanks, Shiv
SCJP, OCE - JSP & Servlets Developer
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Why Serialization?
 
Similar Threads
Object serialization
can somebody explain this?
Is Serialization like taking a picture of memory cells content?
I have a Doubt On Serialization
How the objects are constructed at the time of de-serialization?