Using a long value to specify an array size results in a compiler error unless the value is explicitly cast to type int. In general, the value specifying the array size must be a type that is "int convertable" (can be widened to type int without explicit cast).
Per the
Java Language Specification (
section 15.10)...
The type of each dimension expression within a DimExpr must be a type that is convertible (�5.1.8) to an integral type, or a compile-time error occurs. ...this means, specifically, that the type of a dimension expression must not be long.
But not all int values are valid for specifying an array size. For example, a negative value will result in an NegativeArraySizeException.
Remember, when an object is created (and arrays are objects), the memory for that object is allocated. So if the size of the array is too large, then the OutOfMemoryError will occur.
Per the JLS (
section 15.10.1)...
...space is allocated for the new array. If there is insufficient space to allocate the array, evaluation of the array creation expression completes abruptly by throwing an OutOfMemoryError.