Assertions

The assert keyword enables Java programmers to make use of assertions, a technique that's supposed to improve the reliability of software. An assertion is a Boolean true-or-false expression that represents something that should be true at a spot in the program. Here's an example:

assert speed > 55;

This statement asserts that the speed variable has a value greater than 55. It's a way for a programmer to say, “I expect speed to be greater than 55 at this position, and if it isn't, my program would be completely FUBAR.”

By the way

FUBAR is an acronym popular among computer programmers that means “fouled up beyond all recognition” or “fouled up beyond all repair.” A saltier version that uses a different F word is even more popular. ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.