File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt :assertion errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt :assertion errors" Watch "doubt :assertion errors" New topic
Author

doubt :assertion errors

Satnam Wadhwa
Greenhorn

Joined: Dec 07, 2008
Posts: 25
can somebody help me to figure out assertion errors.?
i am a bit confused in it....
thnx


Regards,<br />Satnam(scjp 5-94%)
Satnam Wadhwa
Greenhorn

Joined: Dec 07, 2008
Posts: 25
also please post about the appropriate use of the assert statements ..
any type of example will do.
thankx
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
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

Joined: Oct 25, 2008
Posts: 2700

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!


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

Please change your name from Sindbaad the Sailor. This is against the naming policy. Use your real name as your display name...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Satnam Wadhwa
Greenhorn

Joined: Dec 07, 2008
Posts: 25
please provide the links to study this topic...
thanks
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Assertions are very well explained in K&B Book.
Mukherji Sandeep
Greenhorn

Joined: Dec 09, 2008
Posts: 6
The following link may help you:
http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html


Mukherji Sandeep<br />Trying Hard to learn java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt :assertion errors