Flow Control and ExceptionsFlow control statements
- Conditional: if, if-else and switch-case
- Looping: for, while, do-while
- Exception handling: try-catch-finally, throw
- Ad hoc flow control: break, continue with or without labels
switch statement
switch(expression){
case ConstantExpression: statement(s);
case ConstantExpression: statement(s);
.
.
.
default: statement(s);
}
- expression: must be char, byte, short, or int, or a compile-time error occurs
- long primitive can be used if type casted to int
- Object reference cannot be used as expression
- Every case expression must be unique
- break statement may be used at the end of a case statement, to discontinue execution.
- There can be at most only one default statement.
- The order of case statements and default can be anything.
break and continue
- A break statement transfers the control out of an enclosing statement. break used within a loop breaks the execution of the current loop. In case of nested loops, the break statement passes the control to the immediate outer loop.
- A continue statement breaks the current iteration and moves to next iteration.
- break and continue with labels.
- Labels specify the target (statement) for continue and break
- continue with label does not jump to the labeled statement but instead jumps to the end of the labeled loop.
- Same label identifiers can be reused multiple times as long as they are not nested.
- Label names do not conflict with the same named identifier(variable, method or class name).
Checked and Unchecked Exceptions
Checked Exceptions
- Checked Exceptions are checked by the compiler to see if these exceptions are properly caught or specified. If not, the code will fail to compile
- Checked exception forces client program to deal with the scenario in which an exception may be thrown
- Checked exceptions must be either declared or caught at compile time
Unchecked Exceptions
- Unchecked exceptions are RuntimeException and all of its subclasses.
- Class java.lang.Error and its subclasses also are unchecked.
- Unchecked Exceptions are not checked by the compiler.
- Runtime exceptions do not need to be caught or declared.
From: http://sitestree.com/?p=4864
Categories:Java Short Notes, SCJP
Tags:
Post Data:2008-08-25 00:56:33
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada