title: When Java evaluates a conjunction (<boolean exp1> && <boolean exp2>), does it eval exp2 if exp1 is false?
body: <p>I'm wondering if it's guaranteed that in a Java program, the boolean expression on the right of a conjunction (exp2 above) will NOT be evaluated as long as the expression on the left (exp1) evaluated to false. I'm wondering because I have an expression like the following:</p>
  
  <pre><code>if (var != null &amp;&amp; var.somePredicate())
     // do something
  </code></pre>
  
  <p>If Java is not guaranteed to stop evaluating <code>(var != null &amp;&amp; var.somePredicate())</code> after it sees that <code>var</code> is null, then it may try to evaluate <code>var.somePredicate()</code> which would throw a NullPointerException. </p>
  
  <p>So my question is, does Java guarantee a certain behavior when it comes to this? Or would it be safer to write</p>
  
  <pre><code>if (var != null)
  {
     if (var.somePredicate())
        // do something
  }
  </code></pre>