June 2004
Intermediate to advanced
848 pages
21h 28m
English
Introduced with Java 1.4, the assert statement helps to debug code and also troubleshoot applications after they have been deployed. You write an assert statement stating some very important condition that you believe will always be true at this point in your program. If the condition is not true, the assertion throws an Error (a Throwable thing that is not intended to be caught). You can do that already in Java. The part that is new is that assertion statements let you choose at run-time whether the assertion checking is on or off.
There are two key pieces to using asserts.
First, you sprinkle assert statements at a few critical places in your program. For example, after calculating ...
Read now
Unlock full access