What is Serialization in Java?
It is the concept of transferring the objects (data) of classes from the RAM to any other location outside the RAM. To get Serialization Homework Help contact tutorspoint.com
Example:
- Transferring the state of an object from RAM to hard disk.
- Transferring the state of an object from RAM to a storage device in another system with the help of a network.
We can’t transfer objects of all classes from RAM to other locations outside RAM.
- There is an interface by name serializable. It is a zero-body interface i.e. it has no function definitions.
- The object of classes that implement serializable. Interface only, is eligible for serialization.
- Object output stream class helps us in transferring the objects of classes from our program (i.e. RAM) to other locations.
- Similarly object input stream class helps us in transferring the objects of classes from other locations to our program.
- Object output stream class has a method by name write object (). It takes, the object of a class that implements a serializable interface, as an argument, or in other words, it takes the serializable interface reference which
- points to the object of a class that implements this interface, as an argument.
- The object of the object output stream class on which the write object () method is called holds the address of the destination location to which the object is to be transferred.
Example:
File output stream for = new file output stream (“file1.obj”);
Object output stream oos = new object output stream (FOS);
Oos. write object (serializable s)
Aa1 = new A ();
Explanation:
In the above example, the object of the file output stream contains the address of the file which is present in the hard disk. Fos is made available to the object of the object output stream class oos. Now on oos, we call the write object () method. In this way address of the destination is made available to write the object () method in which the object is to be written. We can’t transfer objects of all classes from RAM to other locations outside RAM.