title: Using static variables for Strings
body: <p>below content is taken from 
  <a href="http://docs.blackberry.com/en/developers/deliverables/5580/Using_static_vars_for_strings_447038_11.jsp" rel="noreferrer">Best practice: Writing efficient code</a>
  but i didn't understand why </p>
  
  <pre><code>private static String x = "example";
  </code></pre>
  
  <p>faster than </p>
  
  <pre><code>private static final String x ="example";
  </code></pre>
  
  <p>Can anybody explain this.</p>
  
  <blockquote>
    <h2>Using static variables for Strings</h2>
    
    <p>When you define static fields (also
    called class fields) of type String,
    you can increase application speed by
    using static variables (not final)
    instead of constants (final). The
    opposite is true for primitive data
    types, such as int.</p>
    
    <p>For example, you might create a String
    object as follows:</p>
  
  <pre><code>private static final String x = "example";
  </code></pre>
    
    <p>For this static constant (denoted by
    the final keyword), each time that you
    use the constant, a temporary String
    instance is created. The compiler
    eliminates "x" and replaces it with
    the string "example" in the bytecode,
    so that the BlackBerry® Java® Virtual
    Machine performs a hash table lookup
    each time that you reference "x".</p>
    
    <p>In contrast, for a static variable (no
    final keyword), the String is created
    once. The BlackBerry JVM performs the
    hash table lookup only when it
    initializes "x", so access is faster.</p>
  
  <pre><code>private static String x = "example";
  </code></pre>
    
    <p>You can use public constants (that is,
    final fields), but you must mark
    variables as private.</p>
  </blockquote>