Java switch statement04:33

  • 0
Published on May 3, 2017

Java tutorial for beginners playlist

Switch statement in java provides a way to select one of the many different actions.

You must use a break statement after each case block to keep execution from faillng through remaining test cases.

If multiple cases need to have same action, then they can be stacked together

Switch statement rules
1. Multiple case labels but only a single default label.
2. Default label executes when no matching value is found in the case labels.
3. Use break statement to exit a switch case
4. Without break it will just fall through
5. Prior to Java 7, switch control expressions could be integer/character only. Now, String objects are allowed
6. Case statements are executed in sequential order.
7. Use if-else statement when test expressions are based on ranges of values or conditions
8. Use switch to improve readability and where test conditions are based on single integer, enumerated type or string object

Enjoyed this video?
"No Thanks. Please Close This Box!"