UP | HOME
../../

Assertions in Java

1 Overview

  1. Java Assertions Slides: [from Lehigh.edu (Java 1.4 but still good)] PDF PPT
  2. Excerpts from http://www.javapractices.com/
    1. Assertions in general
    2. Assert use cases
    3. Force enabling of assertions
    4. Assert is for private arguments only

2 An Example

  1. Small Set of Integers written in Java

3 Java Programming With Assertions by Oracle.com

  1. Assertions are part of language definition. Not macro based.
  2. E1 is a boolean expressions. E2 is an expression that has a value.
  3. assert E1 ; When the system runs the assertion, it evaluates E1 and if it is false throws an AssertionError with no detail message.
  4. assert E1 : E2 ; The AssertionError constructor uses the string value of Expression2 to generate a detailed message when E1 is false.

4 References

  1. Oracle.com, Java Programming With Assertions, http://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html, 2016. Required Reading.
  2. http://www.javapractices.com/ Assertions Writeup Required Reading.
  3. "I am studying for … Oracle Java SE Certification and I saw this question …" http://stackoverflow.com/questions/15072956/ Required Reading.

5 End


Copyright © 2016 pmateti@wright.edu www.wright.edu/~pmateti 2015-09-03