Technically, Java doesn't have a 2D array. What it has is an array of arrays. With this it is possible for each of the rows to have a different number of columns. Practically speaking though, you can design your program if you want so that all rows have the same number of columns, or in effect, a 2D array.
Given int grid grid is an array of arrays
grid is row '0' of the grid which returns int which is an array representing one row.
So grid.length is the number of columns in row '0', and if in our application all rows have the same length then this length would then be assumed to hold true for all rows.