You're hitting a limit of the particular JVM you're using, or your system memory.
You're trying to allocate an array which will take up ~4GB of contiguous memory. I'd expect a 64-bit JVM on a machine with enough memory to handle that without any problems, but different JVMs may have different limitations. For example, I'd expect any 32-bit JVM to struggle with that.
The good news is that allocating an array that large is almost never required in regular programming. If you do need it, you'll need to make sure you work in an environment that supports it.
Even on my machine that can handle your example, if I increase the size further I get one of two errors, either the one you got:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
or for 2147483646 or 2147483647:
Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
(The first happens somewhere between 1064000000 and 1065000000 on my machine.)