2.Flow Control, Assertions And Exception Handing

1.1assertions may be used to validate the input parameters of a private method. This is because, private methods are called only by the developer of the class. Therefore, if a private method is called with an invalid parameter, this problem should be rectified at the development stage itself. It cannot occur in the production stage, so there is no need to throw an explicit exception.
If the boolean expression is false, a java.lang.AssertionError is thrown. AssertionError extends from java.lang.Error.
The second operand can be null but it cannot be void. In the above case, if value is not 10, it will throw new AssertionError(null).

1.2 assert <boolean_expression> : <any_expression_but_void>;
1.3 Each enable or disable modifies the one before it. This allows you to enable assertions in general, but disable them in a particular package:
java -ea -da:<package>... myPackage.myProgram


2.break cannot be used outside of a loop or a switch
3.continue cannot be used outside of a loop(continue can be used only inside a 'for', 'while' or 'do while' loop.)

4            int x;
//            while (false) { x=3;System.out.println(x); }    //Unreachable code   
            if (false) { x=3; System.out.println(x); }
           
            for( int i = 0; i< 0; i++) x = 3 ;            
//            for( int i = 0; false; i++) x = 3;              //Unreachable code
            
   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值