**Table of Contents**

*   [What is Assertion in Java?](https://www.upgrad.com/blog/what-is-assertion-in-java-how-to-use-assertion-in-java/#What_is_Assertion_in_Java)
*   [Syntax](https://www.upgrad.com/blog/what-is-assertion-in-java-how-to-use-assertion-in-java/#Syntax)
*   [How to Use Assertion in Java?](https://www.upgrad.com/blog/what-is-assertion-in-java-how-to-use-assertion-in-java/#How_to_Use_Assertion_in_Java)
*   [Why Use Assertions?](https://www.upgrad.com/blog/what-is-assertion-in-java-how-to-use-assertion-in-java/#Why_Use_Assertions)
*   [Where to use Assertions?](https://www.upgrad.com/blog/what-is-assertion-in-java-how-to-use-assertion-in-java/#Where_to_use_Assertions)
*   [How to Disable Assertions?](https://www.upgrad.com/blog/what-is-assertion-in-java-how-to-use-assertion-in-java/#How_to_Disable_Assertions)
*   [Ways to use Assertion in Java](https://www.upgrad.com/blog/what-is-assertion-in-java-how-to-use-assertion-in-java/#Ways_to_use_Assertion_in_Java)
*   [Conclusion](https://www.upgrad.com/blog/what-is-assertion-in-java-how-to-use-assertion-in-java/#Conclusion)

### **What is Assertion in Java?**

The assertion in [Java ](https://www.upgrad.com/blog/how-to-code-compile-and-run-java-projects/)is used to ensure the correctness of any program’s assumptions as the assertion is assumed to be true when it is executed. The Java Virtual Machine throws an error named AssertionError if the assertion is false. The assertion in Java has found its[ application](https://www.upgrad.com/blog/why-java-popular-with-developers/) mainly for testing purposes. Boolean expressions are used along with assertion statements. An assertion is a statement, and the ‘asset’ keyword is used to carry out an assertion in Java. 

### **Syntax**

The following are two ways in which assertion is carried out in Java:

1. assert expression;

2. assert expression1: expression2;

#java 

What is Assertion in Java? How to use Assertion in Java
2 Likes1.85 GEEK