title: int to long assignment
body: <p>I have been trying this int and long conversion where I have tried assigning an <code>int</code> variable to a <code>long</code> variable. The code is as follows:</p>
  
  <pre><code>public static void main(String []args){
      int i = 1024;
      long j = i;
      long k = i*i*i*i;
      System.out.println("j= " +j+ ", k= " +k);
  }
  </code></pre>
  
  <p>So, while printing <code>j</code>, it simply gave an output of <code>1024</code>. But while printing <code>k</code>, it showed an overflow (<code>k</code>=0). I sorted out this problem by using this technique, where I have explicitly casted each <code>i</code> to <code>long</code>. i.e.</p>
  
  <pre><code>public static void main(String []args){
      int i = 1024;
      long j = i;
      long k = ((long)i)*((long)i)*((long)i)*((long)i);
      System.out.println("j= " +j+ ", k= " +k);
  }
  </code></pre>
  
  <p>Now, it showed correct values of both <code>j</code> and <code>k</code>.
  So, I wanted to know why is this needed to cast <code>int</code> in the second case but not in the first one. <code>k</code>, being a <code>long</code> can retain this value after this heavy assignment. But, why it is not been correctly assigned?</p>