Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This could be described in the section <a href="http://docs.oracle.com/javase/specs/jvms/se5.0/html/Concepts.doc.html#19075" rel="nofollow noreferrer">2.17.4 of the JVMS 5.0/6</a></p> <blockquote> <p>2.17.4 Initialization</p> <p>Initialization of a class consists of:</p> <ul> <li>executing its static initializers (§2.11) and </li> <li>the initializers for static fields (§2.9.2) declared in the class. </li> </ul> <p>Initialization of an interface consists of executing the initializers for fields declared in the interface (§2.13.3.1).</p> <p>Before a class or interface is initialized, its direct superclass must be initialized, but interfaces implemented by the class need not be initialized. Similarly, the superinterfaces of an interface need not be initialized before the interface is initialized.</p> <p>A class or interface type T will be initialized immediately before one of the following occurs:</p> <ul> <li>T is a class and an instance of T is created.</li> <li>T is a class and a static method of T is invoked.</li> <li>A nonconstant static field of T is used or assigned. A constant field is one that is (explicitly or implicitly) both final and static, and that is initialized with the value of a compile-time constant expression. A reference to such a field must be resolved at compile time to a copy of the compile-time constant value, so uses of such a field never cause initialization. </li> </ul> <p>Invocation of certain methods in library classes (§3.12) also causes class or interface initialization. See the Java 2 platform's class library specifications (for example, class Class and package java.lang.reflect) for details.</p> <p>The intent here is that a type have a set of initializers that put it in a consistent state and that this state be the first state that is observed by other classes. The static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope. This restriction is designed to detect, at compile time, most circular or otherwise malformed initializations.</p> <p>Before a class or interface is initialized its superclass is initialized, if it has not previously been initialized.</p> </blockquote> <hr> <p>The updated version of <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.5" rel="nofollow noreferrer">Initialization in JVMS 8 is in Chapter 5.5</a></p> <blockquote> <p>Initialization of a class or interface consists of executing its class or interface initialization method (<a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.9" rel="nofollow noreferrer">§2.9</a>).</p> <p>A class or interface may be initialized only as a result of:</p> <ul> <li>The execution of any one of the Java Virtual Machine instructions <code>new</code>, <code>getstatic</code>, <code>putstatic</code>, or <code>invokestatic</code> that references the class or interface (<a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.new" rel="nofollow noreferrer"><code>§new</code></a>, <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.getstatic" rel="nofollow noreferrer"><code>§getstatic</code></a>, <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.putstatic" rel="nofollow noreferrer"><code>§putstatic</code></a>, <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.invokestatic" rel="nofollow noreferrer"><code>§invokestatic</code></a>).<br> All of these instructions reference a class directly or indirectly through either a field reference or a method reference.<br> Upon execution of a new instruction, the referenced class or interface is initialized if it has not been initialized already.<br> Upon execution of a <code>getstatic</code>, <code>putstatic</code>, or <code>invokestatic</code> instruction, the class or interface that declared the resolved field or method is initialized if it has not been initialized already.</li> <li>The first invocation of a <code>java.lang.invoke.MethodHandle</code> instance which was the result of resolution of a method handle by the Java Virtual Machine (<a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.5" rel="nofollow noreferrer">§5.4.3.5</a>) and which has a kind of 2 (<code>REF_getStatic</code>), 4 (<code>REF_putStatic</code>), 6 (<code>REF_invokeStatic</code>), or 8 (<code>REF_newInvokeSpecial</code>).</li> <li>Invocation of certain reflective methods in the class library (<a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.12" rel="nofollow noreferrer">§2.12</a>), for example, in class <code>Class</code> or in package <code>java.lang.reflect</code>.</li> <li>The initialization of one of its subclasses.</li> <li>Its designation as the initial class at Java Virtual Machine start-up (<a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.2" rel="nofollow noreferrer">§5.2</a>).</li> </ul> <p><strong>Prior to initialization, a class or interface must be linked, that is, verified, prepared, and optionally resolved</strong>.</p> <p>Because the Java Virtual Machine is multithreaded, initialization of a class or interface requires careful synchronization, since some other thread may be trying to initialize the same class or interface at the same time.<br> There is also the possibility that initialization of a class or interface may be requested recursively as part of the initialization of that class or interface. </p> <p>The implementation of the Java Virtual Machine is responsible for taking care of synchronization and recursive initialization by using the following procedure.<br> It assumes that the <code>Class</code> object has already been verified and prepared, and that the <code>Class</code> object contains state that indicates one of four situations:</p> <ul> <li>This <code>Class</code> object is verified and prepared but not initialized.</li> <li>This <code>Class</code> object is being initialized by some particular thread.</li> <li>This <code>Class</code> object is fully initialized and ready for use.</li> <li>This <code>Class</code> object is in an erroneous state, perhaps because initialization was attempted and failed.</li> </ul> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload