
I've gotten some questions related to Serialization concept in Java.Here are the questions as follows.
Purpose:
"The purpose of Serialization in Java is to persist an object for future use or need from other network place."
- I understand the serialization is often used when we need to have a persisted object in software.What is its responsibility come in the persisted object concept?! Without serialized object, can't we make an object persisted?
- A serialVersionID is used when we need to maintain serialization compatibility between versions( Each class object has its version and it will change when any class members change.But how will it be generated when we don't define it explicitly.
=>A1. We can, with Database server or file in general way.And an object serialization concept obviously has unique advantage that is you can use exactly same object on any JVM.
In other persistence ways, they just hold data persistently and here serialization in Java hold not only data but also the object which is holding data.
Problem1:
First of all, I had the following exception, and immediately see the exception description on java api document online.
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:and guess the cause which is serialVersionUID is different from an object transfering from RMI server..
java.io.InvalidClassException: ClassA ; local class incompatible: stream classdesc serialVersionUID = 204317070979582118, local class serialVersionUID = 5826146587350558648
at Someclass.somemethod()...
But I did first time to an object on client machine JVM to declare an long value has same serialVersionUID of RMI server object, but it failed..
Because server object's UID has been generated by JVM, which means it wasn't declared explicitly on that object..
my client object UID wasn't compared with server's..
so I ask management team leader to replace server object to declare UID explicitly and my client object has same one.
then this problem has gone in an air!!
References:
Java Object Serialization Specification Table of Contents
Versioning of Serializable Objects
Serialization - java.io.InvalidClassException when reading serialized object from stream
***Studying An article***
This article is also giving you good understanding of Serialization API.
Article Discover the secrets of the Java Serialization API
and put some copies here a fresh and interesting fact of it from my point of view.
1. as object caching
2. Caching Objects in the Stream
3. version control
performance issues
3:
An object is marked serializable by implementing the java.io.Serializable interface,
which signifies to the underlying API that the object can be flattened into bytes
and subsequently inflated in the future.
1:
To wit, when we create an object with the new keyword, the object's constructor is called only when a new instance of a class is created. Keeping that basic fact in mind, let's revisit our animation code.
1:There is, however, a strange yet crafty solution.
grammar:Notice that both methods are (and must be) declared private, proving that neither method is inherited and overridden or overloaded.
grammar:So, even though those specialized private methods are provided, the object serialization works the same way as far as any calling object is concerned.
1:(note that the bytes are written and read in cleartext with no obfuscation at all)
1:Serialization in Java is simple to instigate and almost as simple to implement. Understanding the three different ways of implementing serialization should aid in bending the API to your will. We have

No comments:
Post a Comment