• Dear Guest, Please do NOT forget to join our JAVA JOBS (ONLY) FACEBOOK GROUP to be aware of latest JAVA openings, and you may also post any JAVA related queries/jobs.

What is meant by Serialization ?

Re: serialization

wat is serialization?
Serialization is the process of storing object content in a file.
the classes whose object is stored in a file must implements the Serializable interface.
Serializable interface do not contain any method. So it is also called Tagging or Marked interface.
Re: What is Serialization

- Write Object state into secondary storage device (IO Stream).

- Serializable is an interface. Which doesn't have any methods. it's marked or tagged interface.

- It will inform the JVM that implemented Class state should be serialize. Except transisent data type instance variable.
Re: What is Serialization

Serialization is nothing but converting a java object into its persistent state. To achieve serialization, following steps need to be followed :
- Create a class that implements the java.io.Serializable interface.
- Use the readObject() and writeObject() methods to read and write the persistent state of the object.

In the following example, we are serializing and de-serializing the object called SerializableClass. SerializableClass contains one serializable member which is an Integer counter

Example :

import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.ObjectInputStream; 
import java.io.ObjectOutputStream; 
import java.io.Serializable; 

public class SerializableClass implements Serializable { 
    private static final long serialVersionUID = 1L; 
    private Integer counter = new Integer(0); 

    public Integer getCounter() { 
        return counter; 

    public void setCounter(Integer counter) { 
        this.counter = counter; 

    public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException { 
        SerializableClass sc = new SerializableClass (); 
        System.out.println("Counter value : " + sc.getCounter()); 
        // Now set the counter to 100 
        sc.setCounter(new Integer(100)); 
        System.out.println("Counter value before serialization : " + sc.getCounter()); 

        System.out.print("Serializing the object to disk... ");         
        FileOutputStream fos = new FileOutputStream("serializableclass.ser"); 
        ObjectOutputStream ostream = new ObjectOutputStream(fos); 
        System.out.print("Now Deserializing the object from disk... "); 
        FileInputStream fin = new FileInputStream("serializableclass.ser"); 
        ObjectInputStream instream = new ObjectInputStream(fin); 
        SerializableClass sc1 = (SerializableClass)instream.readObject(); 
        System.out.println("New Object created from serialized version on disk..."); 
        System.out.println("Counter value of object from disk : " + sc1.getCounter()); 
        System.out.println("Original Object = " + sc.getCounter() +  
                           " Deserialized object = " + sc1.getCounter()); 


Serialization is the state of saving the object and its instance variables.A class must implement the Serializable interface before its objects can be
what is serialization?
Java object serialization is used to persist Java objects to a file, database, network, process or any other system. Serialization flattens objects into an ordered, or serialized stream of bytes. The ordered stream of bytes can then be read at a later time, or in another environment, to recreate the original objects.

Java serialization does not occur for transient or static fields. Marking the field transient prevents the state from being written to the stream and from being restored during deserialization. Java provides classes to support writing objects to streams and restoring objects from streams. Only objects that support the java.io.Serializable interface or the java.io.Externalizable interface can be written to streams.
Serialization is those methodology of converting a object under a stream of bytes in place will store the object alternately transmit it on memory, An database, or An record. Its principle reason for existing is on spare the state of an article in place should have the ability should reproduce it The point when required. Those opposite procedure will be called deserialization.