1/13
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is object serialization?
The process of flattening objects so they can be stored on disk or transmitted through a data stream.
How do you make a class serializable?
By implementing the java.io.Serializable
interface.
What is the role of ObjectOutputStream
in serialization?
It is used to serialize objects and write them to an OutputStream using the method writeObject(Object obj)
.
How do you de-serialize an object?
By using ObjectInputStream
to read the object from an InputStream with the method readObject()
.
What happens if you try to serialize a class without implementing Serializable
?
The object will not be serialized or de-serialized.
Are static properties serialized?
No, static properties are not saved during serialization.
What is an InvalidClassException
in serialization?
An exception thrown when the serial version UID of a class does not match between serialization and de-serialization.
What is the serial version UID?
A 64-bit secure hash of a class’s full description used for versioning during serialization and de-serialization.
How can you manually set the serial version UID of a class?
By defining a private static final long serialVersionUID
field with a specific value.
What is meant by object graph serialization?
Serialization must preserve the entire object graph, serializing all objects reachable from the original object.
What does the Externalizable
interface allow you to do?
It allows developers to specify which fields of an object should be serialized, using the methods writeExternal
and readExternal
.
What does the transient
keyword do in serialization?
It prevents a specific field from being serialized.
What is the default process for de-serialization?
It involves reading the class type from the stream, constructing an object from its highest serializable superclass, and reading field states from the stream.
How can you customize serialization and de-serialization?
By implementing the writeObject
and readObject
methods in the class.