Overview

Note! The 2.7.5 release will most likely be the last release in the 2.X series. Development of C4J is continued at C4J second generation.

Contracts for Java (C4J) is a Design By Contract (DBC, see Wikipedia DBC definition and Eiffel DBC docs) framework for Java 1.5 and later. The primary goal for C4J is ease of use. DBC is about design and quality, aspects of programming that a lot programmers don't spend enough time and energy on.
Therefore a DBC framework must be simple and painless to use. At the same time the framework must be powerful.
C4J is simple and powerful.

I am not going to try to convince any readers that DBC indeed is a very powerful design and quality assurance technique, so if you are not already convinced of that, please follow the links above and you may be convinced to try this tool out! These are my favorites though:
  • To be able to define meaningful contracts you are forced to split lengthy methods in to small, well defined, methods with a single responsibility. This single "side effect" of DBC has very positive effects on the code quality, maintainability, and readability.
  • Your tests are verified against the real usage of your application, not against some test cases that may not even be real use cases.
  • If you are dealing with legacy code that you are afraid of refactoring, contracts are perfect to add to existing code with no risk involved.