Error in this program for int array Can anyone explain why these two cases behave differently?
class MainOutOfMemoryError {
/*
case1:doesn't give me any error
static final int s = 1024 * 1024 * 1024 * 1024 * 1024;
public static void main(String[] args) {
// we cant declare local variables as static
int[] i = new int[s];
System.out.println(s);
}
*/
// case2:gives error
static final int SIZE = 2 * 1024 * 1024;
public static void main(String[] a) {
int[] i = new int[SIZE];
System.out.println(SIZE);
}
}
ints give anOutOfMemoryError? That's only 8 MB.