title: Compile-time constants and variables
body: <p>The Java language documentation says:</p>
  
  <blockquote>
    <p>If a primitive type or a string is defined as a constant and the value
    is known at compile time, the compiler replaces the constant name
    everywhere in the code with its value. This is called a compile-time
    constant.</p>
  </blockquote>
  
  <p>My understanding is if we have a piece of code:</p>
  
  <pre><code>private final int x = 10;
  </code></pre>
  
  <p>Then, the compiler will replace every occurrence of <code>x</code> in the code with literal <code>10</code>.</p>
  
  <hr>
  
  <p>But suppose the constant is initialized at run-time:</p>
  
  <pre><code>private final int x = getX(); // here getX() returns an integer value at run-time.
  </code></pre>
  
  <p>Will there be any performance drop (howsoever negligible it may be) compared to the compile-time constant?</p>
  
  <hr>
  
  <p>Another question is whether the below line of code:</p>
  
  <pre><code>private int y = 10; // here y is not final
  </code></pre>
  
  <p>is treated in same way as compile-time constant by the compiler?</p>
  
  <hr>
  
  <p>Finally, what I understand from the answers are:</p>
  
  <ol>
  <li><code>final static</code> means compile-time constant</li>
  <li>just <code>final</code> means it's a constant but is initialized at run-time</li>
  <li>just <code>static</code> means initialized at run-time</li>
  <li>without <code>final</code> is a variable and wouldn't be treated as constant.</li>
  </ol>
  
  <p>Is my understanding correct?</p>