title: How serialversionID is working in deserialization in java
body: <p>I have a class like</p>
  
  <pre><code>class Stundent
  {
     private static final long serialVersionUID = 1L;
  
       private int no;
       private String name;
  
      //setters and getters
  }
  </code></pre>
  
  <p>And then i used the following code for serialization &amp; deserialization</p>
  
  <pre><code>public class Serialization{
  
      public static void main(String args[]) throws Exception {
          File file = new File("out.ser");
          FileOutputStream fos = new FileOutputStream(file);
          ObjectOutputStream oos = new ObjectOutputStream(fos);
  
          SerializeMe serializeMe = new SerializeMe(1);
          oos.writeObject(serializeMe);
          oos.close();    
      }
  }
  
  
   public class DeSerialization{
  
      public static void main(String args[]) throws Exception {
  
         File file = new File("out.ser");
       FileInputStream fis = new FileInputStream(file);
       ObjectInputStream ois = new ObjectInputStream(fis);
  
      SerializeMe dto = (SerializeMe) ois.readObject();
      System.out.println("data : " + dto.getData());
      ois.close();   
      }
  }
  </code></pre>
  
  <p>After running the Serialization class i changed the serialiversionID to 2 and then i run the second program,then i got like </p>
  
  <pre><code> java.io.InvalidClassException:
  SerializeMe; local class incompatible
  </code></pre>
  
  <p>That means whenever i am performing deserialization 
  serialversionID of Student class is checking.</p>
  
  <p><strong>My doubt is</strong></p>
  
  <p>1)Is it mandatory to have Student class at the time of deserialization ?</p>
  
  <p>2)As per serialization definition, to transfer the java objects as stream of bytes through network we are performing serialization.So if an object is transferred through network ,how the Student class is available in other side.</p>
  
  <blockquote>
    <p>For example in my application every entity(Hibernate entity) is
    Serializable.
        Because my web application exist in different server and my database
        is in differentserver.That is the reason we have implemented 
        Serializable.In this case can u explain how serialization is working?</p>
  </blockquote>
  
  <p>Thanks in advance...</p>