What is serialization in Java?
Serialization is the process of converting an object into a byte stream so it can be stored or transmitted.
Why is serialization used?
To save object state to a file, send objects over a network, or cache objects.
What does serialization include?
Class information, object state, and metadata needed to reconstruct the object.
What interface must a class implement to be serializable?
java.io.Serializable.
Is Serializable a marker interface?
Yes. It has no methods and simply marks a class as serializable.
How do you serialize an object?
Using ObjectOutputStream.
Example of serialization code?
ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(obj);
What is deserialization?
The process of converting a byte stream back into an object.
How do you deserialize an object?
Using ObjectInputStream.readObject().
What exception occurs if class is not serializable?
NotSerializableException.
What keyword prevents a field from being serialized?
transient.
Why use transient fields?
To exclude sensitive or unnecessary data from serialization.
What is serialVersionUID?
A unique version identifier for a serializable class.
Why is serialVersionUID important?
It ensures compatibility between serialized objects and class versions.
Can static fields be serialized?
No. Static fields belong to class, not object state.
Real-world example use of serialization?
Sending objects between client and server in distributed systems.
Key rule to remember?
Serialization = object → byte stream; Deserialization = byte stream → object.
What is the purpose of serialization in Java?
Serialization allows objects to be converted into byte streams for storage, transmission, or later reconstruction.
Why is serialization used for communication?
It enables objects to be sent over networks between different systems.
How does serialization support persistence?
It allows object state to be saved to files or databases and restored later.
Why is serialization useful for caching?
Serialized objects can be stored and quickly reloaded instead of recomputing them.
How does serialization help performance?
Deserializing an object is often much faster than rebuilding it from scratch.
What is cross-JVM serialization use?
It allows objects to be transferred and used across different JVM environments or machines.
What distributed systems benefit from serialization?
Client-server applications and microservices exchanging objects.