title: if statement example issue getting an error in condition and in one scenario no error appearing
body: <p>I am trying to execute the below if statement code, getting an error saying that "Variable j might not have been initialized".</p>
  
  <p>Example 1:</p>
  
  <pre><code>public class PrimitiveTypesChallenge {
  
     public static void main(String[] args) {
  
          int i = 10;
          int j;
          if(i == 10) {
              j = 20;
          }
  
          System.out.println(j);
      }
  }
  </code></pre>
  
  <p>I initialized value for <code>j</code> variable inside the if block.</p>
  
  <p>Example 2:</p>
  
  <pre><code>public class PrimitiveTypesChallenge {
  
     public static void main(String[] args) {
  
          int i = 10;
          int j;
          if(i == 10) {
              j = 20; 
          }
          else {
             j = 30;
          }
  
          System.out.println(j);
      }
  }
  </code></pre>
  
  <p>In both examples if conditions are true however in the example 1 getting an error and example 2 not getting an error. I am so confusing with these two scenarios. 
  Can someone help me to understand the whole concept behind this?</p>