Serialization Section Index | Page 2
Is there any way to save the state of an object of a class which does not implement Serializable or Extenalizable?.
Yes. You will have to write the value of each and every instance
variable into the persistent storage.
If there are 100 variables, you will have to store each of them individually. If some of the ...more
Is there any significant performance gain in serialization from declaring instance variables as transient?
Is there any significant performance gain in serialization
from declaring instance variables as transient?
Are methods also serialized along with the data members?
No. Method bodies do not hold any information
on the state of an object, so they are not needed
in order to save or restore the state.
Where can I find the official documentation of the Sun Java SDK tools?
You can find the official Sun documentation for all of the
tools in the Java 2 SDK including javac, java, javadoc, appletviewer,
jar, jdb, javah, javap, extcheck, rmic, rmiregistry,
rmid, serialve...more
Why should I implement readObject() even if I don't implement writeObject()?
It's a good idea to think of deserialization as yet another
public constructor. So, if you have any post-construction
activities that you want your object to deal with
such as initialization of t...more
How can an applet read a serialized object residing in the same directory?
Normally when de-serializing from a file one would use a
FileInputStream. However, in the case of an untrusted applet you can use an
InputStream derived from the applet's document base URL.
To ...more
How can I modify a serialized object which is stored in a file if the file contains a large number of objects?
The short answer is that you probably can't without deserializing the objects and reserializing and rewriting the objects.
The serialized format is truly a stream-oriented protocol and does not...more
How can I serialize an object into a byte array?
Wrap an ObjectOutputStream around
a ByteArrayOutputStream. Serializing
an object to the ObjectOutputStream will
then store the object in the byte array:
ByteArrayOutputStream baos = new ByteArra...more
What is a serialized bean?
You can deliver a bean as either its bytecode (compiled Java code) or as a serialized object (after the bean instance is serialized to a file (*.ser)). The difference is that when you load the bea...more
What is ObjectStreamField used for?
Starting with Java 2 Standard Edition, version 1.2, instead of using the transient keyword to define what fields are serializable within a class, you may create an array of ObjectStreamField objec...more
What is ObjectStreamClass used for?
The ObjectStreamClass is used to check if the version of a serialized class (.ser file) is compatibile with the version of a class in memory/loadable from the CLASSPATH.
See How can I programmati...more
What is an object graph?
When used in connection with serialization, an object graph is a
tree structure rooted at the object you
have written to the ObjectOutputStream. The branches and
leaves of the tree are all the o...more
How can I change the names of instance variables in a class which is Serializable and still be able to read serialized files from a previous version of the class? If I use serialver to create a version ID then implement readObject(), how would I know in which order to read in the instance variables from the old serialized files?
One way to solve this is to override the readObject() instance method in the class which you are serializing and whose variable names have changed.
In this method, you can use the ObjectInputS...more
Can a Vector or a Hashtable be serialized and deserialized?
Both these classes implement Serializable, and have
been designed for serialization. So yes, they can be serialized.
One thing you have to watch out for, though, is that in order to
serialize ...more
Is there a way to serialize an object as an XML document?
The Java serialization mechanism uses an efficient, compact format for encoding information about class structure and the values for instance variables. The eXtensible Markup Language (XML) provi...more