Serialization in java example

    when serialization is required in java
    when to use serialization in java
    why do we need serialization in java
    java сериализация десериализация
  • When serialization is required in java
  • Serialization in java w3schools...

    Serialization in java

  • Serialization in java
  • What is deserialization in java
  • Serialization in java w3schools
  • Serialization and deserialization in java
  • Advantages of serialization in java
  • Serialization and Deserialization in Java with Example

     

    Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory.

    This mechanism is used to persist the object.  
    The byte stream created is platform independent.

    Serializable interface in java

    So, the object serialized on one platform can be deserialized on a different platform. To make a Java object serializable we implement the java.io.Serializable interface. The ObjectOutputStream class contains writeObject() method for serializing an Object. 
     

    public final void writeObject(Object obj)
    throws IOException


    The ObjectInputStream class contains readObject() method for deserializing an object. 
     

    public final Object readObject()
    throws IOException,
    ClassNotFoundException

    Advantages of Serialization 

    1. To save/persist state of an object. 
    2. To travel an object across a network.

     

    Only the objects of those classes can be serialized which are implementing

      how serialization works in java
      why serialization required