title: Java deserialization: final variable value is not assigned
body: <p>I'm exploring Java Serialization and Deserialization but wonder how Deserialization works.</p>
  
  <p>Here is my Serialization and Deserialization Code:</p>
  
  <pre><code>import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  public class Testing{
      public static void main(String[] args){
          Serial obj = new Serial();
          Serial ObjNew = null;
          try{
             FileOutputStream fob= new FileOutputStream("file.src"); 
             ObjectOutputStream oob= new ObjectOutputStream(fob);
             oob.writeObject(obj);
             oob.close();
          }catch(Exception fnf){
              fnf.printStackTrace(System.out);
          }
          try{
              FileInputStream fis = new FileInputStream("file.src");
              ObjectInputStream ois = new ObjectInputStream(fis);
              ObjNew=(Serial)ois.readObject();
          }
          catch(IOException | ClassNotFoundException fnf){
              fnf.printStackTrace(System.out);
          }
          System.out.println("OLD: "+obj);
          System.out.println("NEW: "+ObjNew);
  
      }
  }
  </code></pre>
  
  <p>Here Serializable Class Code:</p>
  
  <pre><code>import java.io.Serializable;
  public class Serial implements Serializable {
      private final String ok="DONE";
      @Override
      public String toString(){
          return ok;
      }
  }
  </code></pre>
  
  <p>Everything is working fine with above code.
  But When I try to Deserialize the Object with this code.</p>
  
  <pre><code>import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  public class Testing{
      public static void main(String[] args){
          Serial ObjNew = null;
          try{
              FileInputStream fis = new FileInputStream("file.src");
              ObjectInputStream ois = new ObjectInputStream(fis);
              ObjNew=(Serial)ois.readObject();
          }
          catch(IOException | ClassNotFoundException fnf){
              fnf.printStackTrace(System.out);
          }
          System.out.println("NEW: "+ObjNew);
  
      }
  }
  </code></pre>
  
  <p>and I just changed the value of <code>String ok="Do";</code> in Serializable Class Just to test Deserialize output.</p>
  
  <p>But it just printing <code>Do</code> instead of the value <code>DONE</code> that stored in file. 
  Why it is printing just <code>Do</code>? 
  <strong>why it not reading the value from file?</strong>
  Any Help?</p>