Basics
This lesson discusses the basics of Serialization in Java.
We'll cover the following...
Question # 1
What is Serialization?
Encoding an object as a byte stream is called serializing the object. Once an object has been serialized, its encoding can be transmitted from one running virtual machine to another or stored on disk for deserialization later.
Serialization is mostly used in network programming. The objects that need to be transmitted through the network have to be converted into bytes. Serialization can also be used to store objects on disk or in a database. Other uses of serialization include passing serialized objects as parameters to functions or program running on a remote machine, also known ass RMI (Remote Method Invocation).
Any class can become serializable by implementing the interface Serializable
. The Serializable
interface is just a marker interface in that it doesn't have any methods. Serialization machinary is provided through two classes ObjectInputStream
and ObjectOutputStream
. The below class is serializable:
Serializable class example
class EducativeCourse implements Serializable {
private String name = "Java Interview Bible";
private int lessons;
private int likes;
}
Serialization can also be controlled ...