• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Serialization

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please answer me the following questions.

1. What happens when we serialize a class at the JVM level.
2. Why do we need to serialize a class to send it across network.
3. What happens if we dont serialize a class.

Thanks & Regards,
Ritu
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well,I think you must try to understand first what is Serialization ,so below shown is the link which will help you to understand this.


http://www.mactech.com/articles/mactech/Vol.14/14.04/JavaSerialization/index.html


After going through this,you refer to another link which consist of example for Serialization actualy where it is used mostly.From the below shown link just refer to topic "Example: Sensitive Information"

http://www.acm.org/crossroads/xrds4-2/serial.html



i hope it helps you.
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First up, it's important to note that classes don't get serialized - objects (class instances) get serialized.

1. What happens when we serialize a class at the JVM level.


From a high-level point of view, the object's state is transformed into a representation that can be used outside of the JVM, e.g. in a different JVM. There are different kinds of serialization supported by the JVM. The one that uses ObjectOutputStream produces a binary representation that can only be deserialized by a JVM. Another one use sthe java.beans.XMLEncoder class, and produces an XML representation if the class conforms to the JavaBenas specification.

2. Why do we need to serialize a class to send it across network.


Serialization is the process that turns an object that exists inside of a JVM into something that can be used outside of it. As such, it's a necessary step for sending an object someplace else.

3. What happens if we dont serialize a class.


I'm not sure what you're asking. If you don't serialize an object, then you don't have a serialized representation of it. But that's probaly not what you're asking?
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

Probably Ritu asked if object is not serialized, is there any way to
transfer the object across the network, or something is it must to serialize the object to send it across the network.


For my your description about java.beans.XMLEncoder is quite informative and
I would like to avail its benefits.

Thanks for so nice description!
 
Ritu Kapoor
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, let me elaborate on my third question i.e.

What happens if we dont implement serializable interface and tries to pass it on network or try to save its state.
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ritu Kapoor:
Well, let me elaborate on my third question i.e.

What happens if we dont implement serializable interface and tries to pass it on network or try to save its state.



java.io.NotSerializableException
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are not implemeted the Serilizable interface while writing your object in to file it will throw the java.io.NotSerializableException Exception, so it wont stored into the file.
 
See where your hand is? Not there. It's next to this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!