title: Why doesn't java store large value in long datatype directly but allows to store it indirectly (without using literals)?
body: <p>Here are my 2 examples:<br/>
   1. Directly assigned value to long data type:<br/></p>
  
  <pre><code>long a = 12243221112432;
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>integer number too large</p>
  </blockquote>
  
  <ol start="2">
  <li><p>But when assisgned like this:</p>
  
  <pre><code>ArrayList&lt;Integer&gt; al = new ArrayList&lt;Integer&gt;();
  al.add(12); 
  al.add(24);
  al.add(32);
  al.add(21);
  al.add(11);
  al.add(24);
  al.add(32);
  
  long a=0;
  
  for(int i=0; i&lt;al.size(); i++){
      a = a*100 + al.get(i);
  }
  System.out.println(a);
  </code></pre>
  
  <p>I get this output:</p>
  
  <blockquote>
    <p>12243221112432</p>
  </blockquote></li>
  </ol>
  
  <p>Why doesn't java throw an error in second example?<br/>
  It isn't allowing to assign large value directly(example 1) but indirectly(example 2) it stores it and also allows me to use it too!<br/></p>
  
  <p>What is the reason for this to occur?<br/>
  Is it because i am using integer in arraylist or something else?</p>
  
  <p><strong>UPDATE</strong><br/>
  Why is the large value stored in 'long a' in second example without using literal L?
  It should have given me an error during 5th or 6th iteration of for loop...</p>
  
  <p><strong>Note</strong><br/>
  My question is not regarding the first example... I am asking why it worked for the second example...
  Dont mark the question duplicate, since the other questions do not have my answer..stated above</p>