reason is integer overflow
as output of 100 * 1024 * 1024 * 1024; is an integer(int) not long
and in long a2 = 100L * 1024 * 1024 * 1024; you are specifying that one of the value is long (here 100L) and multiplication with that value results in long value which gets correctly stored in a2