Implementation of 2d arrays in Java