Boundary checks test the values just inside and outside a valid range.

Boundary Test

BoundaryTest.java
public class BoundaryTest {
    static int readOrDefault(int[] values, int index) {
        if (index >= 0 && index < values.length) {
            return values[index];
        }
        return -1;
    }

    public static void main(String[] args) {
        int index = ;
        int[] values = {10, 20, 30};
        int selected = readOrDefault(values, index);

        System.out.println("selected=" + selected);
    }
}
public class BoundaryTest {
    static int readOrDefault(int[] values, int index) {
        if (index >= 0 && index < values.length) {
            return values[index];
        }
        return -1;
    }

    public static void main(String[] args) {
        int index = ;
        int[] values = {10, 20, 30};
        int selected = readOrDefault(values, index);

        System.out.println("selected=" + selected);
    }
}
public class BoundaryTest {
    static int readOrDefault(int[] values, int index) {
        if (index >= 0 && index < values.length) {
            return values[index];
        }
        return -1;
    }

    public static void main(String[] args) {
        int index = ;
        int[] values = {10, 20, 30};
        int selected = readOrDefault(values, index);

        System.out.println("selected=" + selected);
    }
}
range guard The guard checks lower and upper bounds before indexing the array.
edge case Values such as `-1`, `0`, and the array length reveal off-by-one mistakes.