I was doing boundary check of a 2D array which is array[8][LIMIT]; Then I tried several times and found the LIMIT variable should not be larger than 89489404, otherwise there will be an exception like this:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at testLimit.testLimit.main(testLimit.java:9)
I know that 2D array should be allocated the memory in continuous space but just out of curiosity, how do Java decide this number? If I need to new an 2D array based on user input, how do I check the boundary so that no OutOfMemoryError will be thrown?