title: Getting confused with == and = in "if" statement
body: <p>I know that we cant use assignment operator in if statements in java as we use in any other few languages.</p>
  
  <p>that is </p>
  
  <pre><code>            int a;
  
              if(a = 1) {  } 
  </code></pre>
  
  <p>will give a compilation error.</p>
  
  <p>but the following code works fine, how?</p>
  
  <pre><code>           boolean b;
  
             if(b = true) {   }
  </code></pre>
  
  <p>EDIT : Is this the exception to rule that assignment cant be used in if statement.</p>