O'Reilly logo

Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) by Marcus Green, Bill Brogden

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Assertions

The assertion system is a fairly small topic but you need to know both the syntax of the system and the appropriate use of assertions.

The idea behind assertions is that, at critical points in your program, you can insert a single statement that can check for a required condition and produce a message if the condition does not exist. It is of course possible to write your own code without the assertion system. You could, for example, use if/else blocks or even exceptions to do this type of checking. The assertion system, however, offers a more concise syntax. During the normal run of a program assertions are turned off, so the checking causes no performance overhead.

To take examples from the real world, you might want to ensure ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required