While I understand that for large matrices, there may not be enough ram space. However in this case the value is relatively small (9999). The value is a double (4.0) and thus contains, according to my resources, 8 bytes of data (per double). So in theory, a matrix with n = 9999 (n = number of both the number of columns and rows) would need (9999^2 * 8) bytes in Java (not including any overheads) which is significantly less than my current ram, even if there happened to be a couple of matrices (2-3). The error occurs when matrixA is initialized.
Why is the error happening?
int n = 9999;
double[][] matrixA = new double[n][n];
double[][] matrixB = new double[n][n];
// Matrix Multiply uses standard ijk algorithm to multiply matrixA and matrixB
// and returns a 2d double array (matrix)
double[][] matrixC = MatrixMultiply(matrixA, matrixB);