Serialization Section Index | Page 4
Can I pass Externalizable objects by value using RMI, or do the objects have to implement Serializable directly?
RMI will allow you to pass any object that is serializable according to the serialization specification. This includes objects that implement Externalizable as well as objects that implement Ser...more
If you declare your serialiazable fields using the serialPersistentFields member (see FAQ http://www.jguru.com/jguru/faq/view.jsp?EID=1197) then you should document these fields using the @serial...more
RMI uses serialization as its basic and only mechanism for sending objects across a network. If an object implements java.rmi.Remote, then the object's stub is serialized and sent to the client...more
When using object streams over sockets, I have to flush the streams after each write operation. In fact I even have to flush the output stream soon after creation. Is there a way out of this?
The ObjectOutput interface provides a flush() method, implying that implementations are allowed to buffer the output. The semantics of buffered output are such that if you want the data to be se...more
Sun's "Frequently Asked Questions on RMI and Object Serialization" is available at http://java.sun.com/products/jdk/1.2/docs/guide/rmi/faq.html. This is a list of FAQs taken from the RMI...more
Although it's not obvious, arrays in Java are objects; they have methods you can invoke (toString(), equals(), etc.) and contain instance variables (length). The unnamed array superclass also im...more
My subclass implements Serializable but my superclass doesn't. Both subclass and superclass contain instance variables that need to be saved as part of the state of the subclass. Will serialization save the superclass fields for me?
When you serialize an object, the serialization mechanism works by chaining up the inheritence hierarchy, saving the sate of each Serializable superclass in turn. When serialization reaches the ...more
java.awt.Image does not implement Serializable, so if you need to send it to a stream using serialization you must access the underlying data representation and write that representation out expl...more
The following code defines a simple Externalizable class that provides a main() method which instantiates an object, writes it to a file, restores it, then verifies that the restored object conta...more
A class that implements Externalizable must also: Have a public, no-argument constructor. Provide a writeExternal(ObjectOutput) method to save the state of the object, including the state of any ...more
A class that implements Serializable must also: Have access to a no-argument constructor in its first non-serializable superclass Identify non-serializable data members using the transient keywor...more
How do I handle versioning of my Externalizable classes? Do I have to write a version number to the stream?
Just as with classes that implement Serializable, the serialVersionUID field is checked when reading in Externalizable objects via an ObjectInputStream. If serialVersionUID is not explicitly defi...more
The @serial javadoc tag is used to document the meaning and acceptable values of serialized fields. It appears in a javadoc comment just prior to a field declaration, and is followed by a free-...more
The @serialData javadoc tag is used to document methods which generate a serialization format other than the default. In particular, @serialData is typically used to document the writeExternal() m...more