File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on  Assertion? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on  Assertion?" Watch "Question on  Assertion?" New topic

Question on Assertion?

Seenu Reddy
Ranch Hand

Joined: Apr 03, 2002
Posts: 108
Hi All,
I am new to Assertion topic. Could you please answer my question and explain?

Assuming assertions are enabled, which of these assertion statement throw an error?
a) assert true : true;
b) assert true : false;
c) assert false : true;
d) assert false : false;

My ans : c, d

Thanks,<br />Seenu<br />SCJP1.4,SCBCD1.3,Next-->SCWCD1.4
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
You are correct, the answers should be c and d, and they are easy to verify by writing a test program.

For assertion, there are 2 forms:
1. assert expression1
2. assert expression1 : expression2

expression 1 must result in a boolean expression. Whenever expression1 is false, AssertError will be thrown. Thus, c and d give AssertError.

expression2 is the message that you want to pass to the AssertError. Even you pass in a boolean value, it will be converted to String, and printed out.

Exception in thread "main" java.lang.AssertionError: false
at AssertTest.main(

Details can be found from:


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Seenu Reddy
Ranch Hand

Joined: Apr 03, 2002
Posts: 108
Thanks for your response and explanation.

I agree. Here's the link:
subject: Question on Assertion?
It's not a secret anymore!