Is field's default value guaranteed to be visible among threads?
<p>Discussing <a href="https://stackoverflow.com/a/36385120/2786156">this answer</a> I was wondered why didn't we use sychronization when assigning default values.</p>

<pre><code>class StateHolder {
    private int counter = 100;
    private boolean isActive = false;

    public synchronized void resetCounter() {
            counter = 0;
            isActive = true;
    }

    public synchronized void printStateWithLock() {
        System.out.println("Counter : " + counter);
        System.out.println("IsActive : " + isActive);
    }

    public void printStateWithNoLock() {
        System.out.println("Counter : " + counter);
        System.out.println("IsActive : " + isActive);
    }
}
</code></pre>

<p>This class looks thread safe because access to its fields is managed by a synchronized method. That way, all we have to do is to publish it safely. For instance:</p>

<pre><code>public final StateHolder stateHolder = new StateHolder();
</code></pre>

<p>Can it be considered as a safe publication? I think no, it cannot. Consulting the <a href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.5" rel="nofollow noreferrer">final field semantic</a> (emphasized mine) I figured out that the only thing guarnteeed is that <code>stateHolder</code> reference is not a stale one. :</p>

<blockquote>
  <p>A thread that can only see a reference to an object after that object
  has been completely initialized is guaranteed to see the correctly
  initialized values for that <strong><em>object's final fields</em></strong>.</p>
</blockquote>

<p><code>final</code> field semantic is not concerned about the state of the ojbect referenced to by the <code>final</code> field. That way, another thread might as well see default values of the fields.</p>

<p><strong><em>QUESTION:</em></strong> How can we guarantee memory consistency of the filed's values assigned within a constructor or instance initializer?</p>

<p>I think we have to declare them either <code>volatile</code> or <code>final</code> as that there is no <a href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4.5" rel="nofollow noreferrer">happens-before</a> relationship bethween assigning a reference and constructor invocation. But lots of library classes does not declare fields that way. <a href="http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/String.java" rel="nofollow noreferrer">java.lang.String</a> is an example:</p>

<pre><code>public final class String 
          implements java.io.Serializable, Comparable&lt;String&gt;, CharSequence{
    //...
    private int hash; //neither final nor volatile
    //...
}
</code></pre>