Assertion in Java was introduced in JDK 1.4. Assert is a keyword.
There are two types of assert statements :
- very simple assert statement.
assert <boolean_result>; (After assert there should be a space )
- simple assert statement.
assert< boolean_result> :some literal
By default assert statements will not execute because they are disabled. In order to execute assert statements, we need to supply one of the VM argument:
ea or enable assertions
In order to disable assertion statement explicitly we need to supply another VM argument :
da or disable assertions
By default , every assert statement got disable.
REQUIREMENT OF ASSERTION IN JAVA:
- assertions are used to fix business rules.If at all assert statement is receiving boolean result as “false ” , we will get assertion error. Assertion error is a type of error of a type of Error class.