Java Assertions


Java assertions are wonderful things which help define the desired behaviour of an application. For example the following assertion states that the variable number should be non-negative:

 assert ( number >= 0) 

Unlike exceptions, which can be caught and handled gracefully, an assertion failure indicates that something has gone terribly wrong within the application and causes it to exit. Thus, in the above example, if assertions are switched on and number is equal to -5 the application will crash. Continue reading