| Assertion facility is added in J2SE 1.4. In order to | | | | to false and assertions are enabled, AssertionError |
| support this facility J2SE 1.4 added the keyword | | | | will be thrown at runtime.Some examples that use |
| assert to the language, and AssertionError class. | | | | simple assertion form are as follows.assert value |
| An assertion checks a boolean-typed expression | | | | > 5 ;assert accontBalance > 0;assert |
| that must be true during program runtime | | | | isStatusEnabled();The expression that has to be |
| execution. The assertion facility can be enabled or | | | | asserted runtime must be boolean value. In third |
| disable at runtime. Declaring Assertion Assertion | | | | example isStatusEnabled() must return boolean |
| statements have two forms as given | | | | value. If condition evaluates to true, execution |
| belowassert expression;assert expression1 : | | | | continues normally, otherwise the AssertionError |
| expression2;The first form is simple form of | | | | is thrown.Following program uses simple form of |
| assertion, while second form takes another | | | | assertion//AssertionDemo.javaClass |
| expression. In both of the form boolean | | | | AssertionDemo{Public static void main(String |
| expression represents condition that must be | | | | args[]){System.out.println( |
| evaluate to true runtime.If the condition evaluates | | | | withdrawMoney(1000,500) );System.out. |