Once in a while, a programmer needs to know if a particular condition happens in the code, even after the application has been already deployed to production. At the same time, there is no need to run the check all the time. That is where the branching assert statement comes in handy. Here is an example:
public someMethod(String s){
//any code goes here
assert(assertSomething(x, y, z));
//any code goes here
}
boolean assertSomething(int x, String y, double z){
//do something and return boolean
}
In the preceding code, the assert() method takes input from the assertSomething() method. If the assertSomething() method returns false, the program stops executing.
The assert() method is executed only when the JVM is run with the -ea option. The -ea flag should not be used in production, except maybe temporarily for testing purposes, because it creates the...