Assertion is good utility for prgrammers to get away from doing exception handling at everytime, even though not required while testing or debugging the code; Suppose you have to check some variable's value should never be zero so you could write as assert a!=0;
By the way you may be using this "a" to divide any number, so simply you asserted it, instead of just putting the code inside try catch block, unnecessarily. You want to be 100 % sure that it wont be zero. Therefore the assert provides you save the number of lines also, otherwise you could have made if else or something for check.
Yeah, when development and testing has been done you need not to enable the assertion, because its purpose has been availed while testing was going on. Thankfuly assertion is disabled at runtime as its default setting. You explicitely enable it using -enableassertion or -ea while launching your program.
Simple using assert while testing the code saves undesirable or say it lengthy exception handling everytime something has to be tested. But beware exception handling has its own important role, assertion does not replace exception handling though. I think you got the meaning of sentence.
Joined: Feb 26, 2007
Thanks Chandra for the explanation. You seem to be well conversed in Java. Just curious, Are you a programmer?
Joined: Feb 28, 2007
Thanks for compliments. You can think me like you, who is preparing for exam.