What is meant by Serialization ?

Discussion in 'Serialization' started by sridhar_tota, Sep 18, 2008.

  1. sridhar_tota

    sridhar_tota New Member

    what is serialization?
     
  2. prasant_2cu

    prasant_2cu New Member

    Re: serialization

    the process of writing the the object in byte stream is called serilization.
     
  3. prasant_2cu

    prasant_2cu New Member

    Re: serialization

    the process of writing the the object in byte stream is called serilization.
     
  4. ghana.sahoo

    ghana.sahoo New Member

    Re: 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.
     
  5. vbraojava

    vbraojava New Member

    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.
     
  6. 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 :

    Code:
    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); 
            ostream.writeObject(sc); 
            ostream.close(); 
            fos.close(); 
            System.out.println("Done");         
            
             
            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(); 
            instream.close(); 
            fin.close();     
            System.out.println("Done"); 
             
            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()); 
    
        } 
    
    }
     
  7. Re: What is Serialization


    Is it Funzone or Discussion Forum.
    Here Share your knowledge and clarify your doubt.
     
  8. d_pv2001

    d_pv2001 New Member

    Serialization is the state of saving the object and its instance variables.A class must implement the Serializable interface before its objects can be
    serialized.
     
  9. 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.
     
  10. anand853

    anand853 New Member

    can i do Serialization on static variables?


    anand pasunoori
     
  11. vbraojava

    vbraojava New Member

    Yes you can do.
     
  12. anitha.mca

    anitha.mca New Member


    Static variables cannot be serialized!
     
  13. anneroberts

    anneroberts Member

    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.
     

Share This Page