Enable and Disable Assertion in Java

How to enable and disable Assertion in Java

Assertion are simple check  assumption  made at the beginning of the program to ensure the program is true throughout  provided by  the Java language. For example, the range of age should be in between 18  and above; or cannot be more than 50.
These are the set of expression used in Java that enables you to check the assumption made in a program during throughout the execution of program. An Assertion contain a Boolean expression which is set to be true in the beginning of the program. For Example ,a program has a method that allow the value being passed to it should not be zero and negative, you test this assert by sending a only positive number that is greater than zero by using assert statement in java.

How to Enable and Disable Assertion

Assertion are disabled at run-time during execution of java program .
The command line prompt  -ea or enable assertions is used to enable assertion during run-time execution of the program.
java -ea:AssertDemonstration
The command prompt -da or disable is used to disable assertion during run-time execution of the program
java -da :AssertDemonstration

People who read this post also read :


Nice tutorial. I have also shared some tips on Assertion as Where to use Assertion in Java you may like.

Post a Comment


Twitter Delicious Facebook Digg Stumbleupon Favorites More