J2SE (Java 2 Platform, Standard Edition) 1.4 adds a simple assertion facility to Java. At the simplest level, an assertion checks a boolean-typed expression that a developer specifically proclaims must be true during program runtime execution. To support the new assertion facility in J2SE 1.4, the Java platform adds the keyword assert to the language, an AssertionError class, and a few additional methods to java.lang.ClassLoader. This article, the first in a two-part series, covers the mechanics of using the new assertion facility. Part 2 will cover the methodological use of assertions by comparing Java's simple assertion facility with Design by Contract and examining the design and implementation issues of using assertions. (2,700 words; November 9, 2001)
2. J2SE 1.4 premieres Java's assertion capabilities, Part 2
Part 1 of this two-part series covered the mechanics of using the new assertion facility introduced in J2SE, (Java 2 Platform, Standard Edition) 1.4. This installment discusses the methodology behind using assertions. Assertions are a valuable tool in assuring program correctness and should not be confused with the program robustness facilitated by Java's exception-handling process. In this article, Wm. Paul Rogers shows how assertions complement exceptions and compares Java's new assertion facility with Design by Contract (DBC). (3,400 words; December 14, 2001)
The importance of employing a good data-validation framework cannot be overestimated. Eventually, someone (maybe even yourself!) is going to reuse the classes you've created. Unless your objects come with a built-in, robust data-validation mechanism that requires little maintenance, you'll need to advise that someone about the valid data ranges accepted by those objects. The core Java API has everything you need to solve this problem in the most elegant way. In this article, you will build a foundation for the data-validation framework whose grown-up version has been implemented successfully in large-scale commercial projects. (1,500 words)