long size = Integer.MAX_VALUE+1;
byte [] b = new byte[size];
-possible loss of precision
How can we make an array of long size?
Array elements are indexed from [0] through [Integer.MAX_VALUE-1],
and that's that. You can make an array whose elements are larger
than a single byte (`new long[N]', for example) and thus get an array
of more than Integer.MAX_VALUE-1 bytes, but you cannot have more than
that many elements.
Incidentally, you might want to print the value of `size' that
you calculate in your example. It might surprise you ...
(By the way: Yes, I really did intend the `-1's above. An int
index value could go one higher, but how could you create the array?
In `new byte[N]', N cannot exceed Integer.MAX_VALUE, which means that
the index cannot exceed N-1, or Integer.MAX_VALUE-1. You could try
to write `new byte[] { 0,0,0,... }' and so on for two giga-values,
but you'd exceed .class file limits long before you got there.)