what is Serialization in java?


Serialization:
It is a process of storing the state of the object in a file.

  • In the case of the distributed computing ,you may get a chance to pass data from one machine to another machine (from one JVM to other JVM) this data can be a primitive data or object data.
  • When you passing the primitive data from one machine to another machine then call by value machine will be used i.e. data will be copy as it is.   
  • When you passing the reference data then call by reference mechanism will be used  i.e. address will be copied from one JVM to another JVM, but there is no use of passing the address .so you need  a different mechanism to pass the object from one JVM to another JVM. so for this  you can use Serialization and Deserialization mechanism.
  • Serialization is a process of storing the data of the object in a serializable file/flat file.
  • Deserialization is a process of recording the data from  serializable file and reconstructing the new object.
  • For this two operations ,there are two subclass provided in java.io package 
    •  ObjectOutputStream 
    •  ObjectInputStream
  •  If you want to serialize object of any class, then that class must implement serializable marker interface .
  •   When you trying to serialize an object whose class is not implementing serializable interface then exception will be thrown as follows:-------
                                                 Java.io.NotSerializableException 

1 comment :