title: When is the static block of a class executed?
body: <p>I have 2 jars, let's call them a.jar and b.jar.</p>
  
  <p>b.jar depends on a.jar.</p>
  
  <p>In a.jar, I defined a class, let's call it StaticClass. In the StaticClass, I defined a static block, calling a method named "init" : </p>
  
  <pre><code>public class StaticClass {
    static {
      init();
    } 
  
    public void static init () {
      // do some initialization here
    }
  }
  </code></pre>
  
  <p>in b.jar, I have a main, so in the main, I expect that the init() method has been called, but actually not. I suspect that is because the StaticClass has not been loaded by the jvm, could anyone tell me</p>
  
  <ol>
  <li>Is my conclusion correct? </li>
  <li>What triggers the jvm to load a class?</li>
  <li>How can I get the static block executed automatically?</li>
  </ol>
  
  <p>Thanks</p>