Which version of Java introduced the 'assert' keyword?

The story behind the answer

Java 1.4 introduced the assert keyword.

The feature arrived with J2SE 1.4, released on February 6, 2002. Its design was standardized through the Java Community Process in JSR 41, adding a compact way for programmers to state conditions they expect to remain true while code runs. The syntax can include an optional detail expression, as in assert balance >= 0 : "negative balance";.

When assertions are enabled and the condition is false, Java throws AssertionError. They are intended primarily for detecting programming errors and checking internal assumptions, not for validating user input or enforcing required application behavior.

One common misunderstanding is that writing assert automatically activates checks. Assertion status is disabled by default at runtime; developers normally enable it with the -ea or -enableassertions option. The keyword also created a compatibility issue for older source code that had used assert as an identifier, which is why Java 1.4 compilers provided source-compatibility controls.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: