Java assert

Contributor(s): Matthew Haughn

Java assert is a keyword in Java that indicates that the programmer believes that a given statement generally remains true all the time.

In Java, the assert keyword is followed by a Boolean true or false statement or an expression that returns a Boolean statement at runtime.

Assertion statements can allow a programmer to test assumptions about their programs. For example, in the case of a program calculating the speed of particles, it can be generally assumed that its speed is slower than the speed of light. If an assert is made in code expressing  “this is true,” an error will be returned in the event that the assert proves not to be true.

When Java assert shows to be true, it can help confirm code and increase confidence. This capacity makes Java assert a quick and effective method of debugging code. Assertions can also make code more manageable for the future by documenting the code’s functionality.

This was last updated in July 2016

Continue Reading About Java assert

Dig Deeper on Java Development Tools



Find more PRO+ content and other member only offers, here.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

Still learning java on my own. Thanks for the tips.


File Extensions and File Formats