Sometime you may require to select one block of code from multiple block of code. To address such requirements java provides switch statement which
					 allows java programmers to select one block from multiple
					block of statements. The syntax of switch 
					statement is: 
switch(expression) {caseconstant-1:// code of case 1 blockbreak;caseconstant-2:// code of case 2 blockbreak;caseconstant-3:// code of case 3 blockbreak; . . . . . .caseconstant-N:// code of case N blockbreak;default:// code of default block}
switch statement evaluates it's expression and then selects the matching
					block. The working of switch statement is very similar to if-else if ladder, which means the same
					thing can be achieved using if-else if statement.
Does switch statement moved directly to matching case ?
No, It starts matching from top to bottom, the one that is matched, the code of that block is executed.
A programmer should remember below points while using switch statement in java.
- The expression used in a 
switchstatement should be of typebyte,short,char,int,enumsandString(Java SE 7 and above). Wrapper classesCharacter,Byte,ShortandIntegercan also be used. - A programmer can have any number of 
casestatements within aswitchblock. Eachcasestatement must be followed by thevalueto be compared to and a colon(:). - Each case 
valuemust be unique. Duplicating a casevaluewill result in compile time error. - The type of 
valuefor everycasemust be same as data type ofswitchstatement expression. Each casevaluemust be a constant or a literal. You can not use variables, for examplecasenum1,casenum2are incorrect declaration. - There can be multiple lines of code(statements) for each 
case. - When a 
caseis matched, all the statements of thatcasewill execute until abreakstatement is reached. - When a 
breakstatement is reached, theswitchblock terminates, and the flow of control jumps to the next line after theswitchblock. - Use of 
breakstatement is optional, If not used, all the cases(including codes inside it) after the matchingcasewill execute until abreakstatement or end ofswitchstatement is reached. - The default case in 
switchstatement is optional. It can be used to perform any tasks when no cases is matched. 
Control flow diagram of switch statement
The above diagram shows the control flow of switch statement assuming that you have used break statement in every
 case of switch block
switch case program in Java
classSwitchStatement {public static voidmain(String [] args) {intdayNo = 4; String dayName;switch(dayNo) {case1: dayName ="Sunday";break;case2: dayName ="Monday";break;case3: dayName ="Tuesday";break;case4: dayName ="Wednesday";break;case5: dayName ="Thursday";break;case6: dayName ="Friday";break;case7: dayName ="Saturday";break;default: dayName ="Invalid day";break; } System.out.println("day name = "+dayName); } }
Output:
day name = Wednesday
Programmer can decide whether to use if-then-else if or a switch statement on the basis of readability 
and the expression that the statement is testing. One example is, if-then-else if should be preferred when you want to test ranges of value
 like a>0 && a<10 while switch statement should be preferred to test single value like for a==5 execute this,
  for a==4 to execute that etc.
- Conventionally you should use default statement in last, though it's not mandatory but prefer to follow this.
 - Keywords are case-sensitive, can not use like Switch, SWITCH, switcH etc. Every letter should be small letter.
 - return statement can also be used inside switch cases, once executed the flow will be exited from the method itself.
 - Expressions like a+b, a+b*c etc. can also be used in switch statement.
 


