What is Assertion in java ?

What is assertion in java and why it is used ?


  • Anoop Kumar
    Anoop Kumar
    Assertions are generally part of Unit Testing.
    You are going to test something which are are you expecting.
    Like if you are expecting null then you can assert
    assert i==null : "throw this message"
    Assertions are bydefault disabled so adding assertions will not affect your run time. but when you need it.
    just enable is by sending  jvm parameter -ea.
    example :  java -ea 
    Good one but very less used. everyone is using IDE with debugger.
  • vikaskumar11233
    Assertion are used to verify the correctness of an invariant in the code. They should never be triggered in production code, and are indicative of a bug or misuse of a code path.

You are reading an archived discussion.

Related Posts

guys....i m so eager to design a robot to participate in robowar competition in an all india symposium...can you give some ideas on making that in simple techno and in...
if converting rotating energy is possible , then y can't we use a rotating circular disk with teeth and connecting a number of same type of disk in series with...
we all heard that energy can be neither created nor destroyed...but y the world sufffer from energy scarcity.....are we able to get the same energy from every machines...for example...,electric fan...
Disney’s Ishin-Denshin Project is something where audio could be beamed person-to-person via a simple touch. Huge win for the electronics segment, no? Indeed is! Disney Research has nicknamed their project...
My question is about the heat dissipation in the rail engines. Engines being a mechanical device gets heatedup on continuous working and heat dissipation must be done and nowadays we...