Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt :assertion errors

 
Satnam Wadhwa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can somebody help me to figure out assertion errors.?
i am a bit confused in it....
thnx
 
Satnam Wadhwa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also please post about the appropriate use of the assert statements ..
any type of example will do.
thankx
 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Assert_test
{
public static void main( String args[] )
{
int x=1;
assert x==2:x;
System.out.println("ASSERT DISABLED");
}
}


In this Example, If Assertions are disabled at run-time, Th answer is
ASSERT DISABLED. If Assertions enabled, then the condition x==2, will be false, so an Assertion Error is thrown.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It like a if-statement. If the assert expression results in true: no problem. If it results in false: AssertionError.



Remember that you have to enable assertions!
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please change your name from Sindbaad the Sailor. This is against the naming policy. Use your real name as your display name...
 
Satnam Wadhwa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please provide the links to study this topic...
thanks
 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assertions are very well explained in K&B Book.
 
Mukherji Sandeep
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following link may help you:
http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic