Does the JVM allocate memory for the entire array length * 4 bytes, i.e. 4000 bytes after the above statement
Java will do it as you say, and one more thing is that the memory needs to be contiguous. Because the data of arrar is consecutive, it is necessary to fully allocate it when initializing the array, if there is no contiguous memory, out of mem will occur.
Some space will be needed for the array itself, but it's only about 4 to 8 bytes