Switch case is used when we have number of choices and based on the input choice different task is performed for each choice.

Here is the syntax.

switch(expression) {
   case value :
      // code here
      break; // optional

   case value :
      //  code here
      break; // optional

   default : // Optional
      //  code here
}

Switch Case without Break Example:

package javatutsworld.com;

public class SwitchCaseTest {

    public static void main(String args[]) {
        int i = 3;
        switch (i) {
        case 1:
            System.out.println("Monday");
        case 2:
            System.out.println("Tuesday");
        case 3:
            System.out.println("Wednesday");
        case 4:
            System.out.println("Thursday");
        case 5:
            System.out.println("Friday");
        case 6:
            System.out.println("Saturday");
        case 7:
            System.out.println("Sunday");
        default:
            System.out.println("This is Default");
        }
    }
}

Output:

Wednesday
Thursday
Friday
Saturday
Sunday
This is Default

In above program we did not use Break which is optional that is why matching case is executed and then rest of cases are executed.

Switch Case with Break Example:

package javatutsworld.com;

public class SwitchCaseTest {

    public static void main(String args[]) {
        int i = 3;
        switch (i) {
        case 1:
            System.out.println("Monday");
            break;
        case 2:
            System.out.println("Tuesday");
            break;
        case 3:
            System.out.println("Wednesday");
            break;
        case 4:
            System.out.println("Thursday");
            break;
        case 5:
            System.out.println("Friday");
            break;
        case 6:
            System.out.println("Saturday");
            break;
        case 7:
            System.out.println("Sunday");
            break;
        default:
            System.out.println("This is Default");
        }
    }
}

Output:

Wednesday

In above program we used Break when we want our program flow to come out of the switch body. So whenever matching case is executed a break statement is encountered in the switch body then execution flow would directly come out of the switch and rest of cases will not execute.