Serialization Section Index | Page 3
Can I serialize an object that has native methods?
Method implementations, whether native or pure Java,
are not part of the serialized state of an object.
There is nothing that prevents objects with native methods
from being serialized.
It mi...more
I am able to write an object using ObjectOutputStream but when I try to read the object back using ObjectInputStream I get a StreamCorruptedException. How can I overcome this?
The serialization specification says that a StreamCorruptedException
is thrown:
If the stream header is invalid.
If control information not found.
If control information is invalid.
JDK 1.1.5 or ...more
How can I read and write serialized objects to and from a database?
If your RDBMS supports them, you can store serialized objects as BLOBs.
These are JDBC 2.0 features, but take a look at java.sql.Blob, ResultSet and PreparedStatement for more information.
more
What are the security considerations for serialization?
The Java runtime environment has many features that
contribute to security and robustness in a program.
For example, the runtime environment enforces access
permissions to private, protected, or ...more
Can an object of type Class be serialized?
Yes, it can. Class implements Serializable, so
a object of type Class can be serialized.
Does serialization support encryption?
Not directly. I/O in Java is performed through streams,
and encryption is typically implemented as an algorithm
operating on a stream - the input to the stream is clear text,
the output is encryp...more
Is writing an object to an ObjectOutputStream a thread-safe operation?
Absolutely not!
Serialization, i.e. passing an object reference to the writeObject() method
of ObjectOutputStream,
is not an atomic operation. Serialization involves traversing a
graph of object...more
How has Serialization changed in the Java 2 SE SDK, v1.3?
Serialization has improved in three key ways:
Speed of reading and writing serialized objects was improved up to 40%.
This also dramatically improves RMI performance.
Limit of 64K on the size of ...more
What are the writeReplace() and readResolve() methods used for?
These methods are used to allow an object to provide an
alternative representation for itself within an ObjectStream. Consider for
instance the common means of implementing an enumerated type:...more
How can I programmatically obtain the serialVersionUID for a class?
The following piece of code shows you how to do this
for the class java.lang.String:
String s = new String("test");
Class cl = s.getClass();
long uid = ObjectStreamClass.loo...more
I keep getting a StackOverflowError when I try to serialize my objects. What does this mean and how can I stop it?
Serialization is a recursive process. If your object graph is too deep,
then you could overflow the JVM stack. To prevent this, implement
readObject() and writeObject() and use your superior
kno...more
ObjectOutputStream seems to be holding a reference to all the objects in my large graph, even after I close the stream. This keeps my objects from being garbage collected. Is this a bug?
ObjectOutputStream holds a reference to all the objects in the
graph so it can handle circular references by noticing when an object has
already been serialized. The only way to clear these refer...more
Why would I want to implement Externalizable instead of Serializable?
By implementing Externalizable yourself you can win performance
at the cost of flexibility and extra code to maintain.
If you implement Externalizable yourself you stream the data directly withou...more
How can I make a deep copy of an object using serialization?
See http://www.jguru.com/jguru/faq/view.jsp?EID=20435.
The javadoc documentation for every Swing class contains the warning that "Serialized objects of this class will not be compatible with future Swing releases." What exactly does this mean, and how does it affect how I write my Swing applications?
From the JBuilder documentation:
Serializing JavaBeans
Serializing an object is the process of turning its state into a sequence of bytes that is neither a .java nor a .class file. Why would you ...more