It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes assertions and parameters 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 "assertions and parameters" Watch "assertions and parameters" New topic

assertions and parameters

Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
today's question from examulator gave 1/, 2/, and 3/, as correct answers, but the thing is, i understand that assertions should NOT be used to validate user input, such as parameters given at the command-line etc... but inner methods parameters are okay to be checked by assertions arent they?
here is the question...
Which of the following statements are true?

1 Compiling code with assertions requires a compilation switch
2 Assertions should not be used for parameter checking
3 Programs should not depend on the outcome of assertions
4 The use of assertions requires the code should import java.assert.*

giddee up
Dan Culache
Ranch Hand

Joined: Jan 24, 2003
Posts: 70
That was my understanding too.
DO NOT use assertions to validate parameters for public methods.
DO use assertions for all other parameter validation.
So with the above caveat I believe the answers are:
Sridhar Srikanthan
Ranch Hand

Joined: Jan 08, 2003
Posts: 366
I have written a mail in the afternoon giving feedback about this ambiguity to Marcus. I hope to get a reply
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
thanks for the responses ...
btw //1 is correct because yes, assertions do require a compilation switch.
but //2 is ambiguous as assertions should and should not be used for parameter checking, yes if it is parameters from other methods but no if it is a parameter directly from a user input.
Sri - i would be interested to see what marcus says .
Rahul Gupta
Ranch Hand

Joined: Nov 20, 2002
Posts: 37
Recently I appeared for the SCJP test and there was a question similar to this. But there was not scope for any ambiguity. So dont worry and just have a clear idea of where assertions can or cannot be used. The Exam question will be clear enough and will not confuse you if you know the stuff. Hope that helps

regards,<p>rahul <p>SCJP 1.4<br />--------<br />Life is great, make it meaningful<br />---------------------------------
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
cheers Rahul
I agree. Here's the link:
subject: assertions and parameters
It's not a secret anymore!