Initializing the edge values of 2D array in Java
Could it be that you make too many assumptions? Probably you should really create a new array and not "write the fence" in an existing one. 

I guess this would simplify the code by just creating an all zero arrays for the first and last element of the outer array and an array with only the zero at start and the end for all other rows.

Given your assumptions are correct. Using a function to fill the array would simplify your solution significant. In Java this is done with Array.fill.

private static int[][] initGrid(final int[][] grid) {
    assert grid.length &gt;= 2;
    final int fence = 0;
    Arrays.fill(grid[0], fence);
    for(int[] row : grid) { 
       row[0] = row[row.length -1] = fence; 
    }
    Arrays.fill(grid[grid.length - 1], fence);
    return grids;
}