title: Why are readObject and writeObject private, and why would I write transient variables explicitly?
body: <p>I am reading the chapter on Serialization in <em>Effective Java</em>.</p>
  
  <ol>
  <li><p>Who calls the readObject() and writeObject()? Why are these methods declared private ?</p></li>
  <li><p>The below is a piece of code from the book</p>
  
  <pre><code>// StringList with a reasonable custom serialized form
  public final class StringList implements Serializable {
      private transient int size = 0;
      private transient Entry head = null;
  
      //Other code
  
      private void writeObject(ObjectOutputStream s)
          throws IOException {
          s.defaultWriteObject();
          s.writeInt(size);
          // Write out all elements in the proper order.
          for (Entry e = head; e != null; e = e.next)
             s.writeObject(e.data);
          }
      }
  }
  </code></pre>
  
  <p>Is there any specific reason the variable <code>size</code> is declared as transient and then in the writeObject method it is explicitly written? If it were not declared as transient, it would have been written anyway, right?</p></li>
  </ol>