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 Dan's questions on assertions: inconsistent? 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 "Dan Watch "Dan New topic

Dan's questions on assertions: inconsistent?

Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
Here are two questions on assertions from Dan's single topic exam:

The correct answers are a, d, f, h for q. 15 and b, d, e for q. 17. Option f states the same in both, but it doesn't show up in q. 17 as correct. However, the real problem is under what circumstances using assertions is appropriate for checking a precondition
Here's what Programming with Assertions states:

Do not use assertions to check the parameters of a public method. An assert is inappropriate because the method guarantees that it will always enforce the argument checks. It must check its arguments whether or not assertions are enabled. Further, the assert construct does not throw an exception of the specified type. It can throw only an AssertionError.
You can, however, use an assertion to test a nonpublic method's precondition that you believe will be true no matter what a client does with the class. For example, an assertion is appropriate in the following "helper method" that is invoked by the previous method...

I think, option f in both questions needs to be defined clearer to comply with assertions usage rules.
[ November 07, 2003: Message edited by: Vad Fogel ]
I agree. Here's the link:
subject: Dan's questions on assertions: inconsistent?
It's not a secret anymore!