permaculture playing cards
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 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 "Assertion" Watch "Assertion" New topic


Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
Hi All,

I was reading tutorial on java which says

1)"Assertions can be used to validate the parameters passed to a private method."
2)"However,assertions should not be used to validate parameters passed to public methods because a public method must check its arguments regardless of whether assertions are enabled or not."

Could any one explain above statements with example code please.........

Thanks in advance,
Naveen Kollipara
Ranch Hand

Joined: Feb 20, 2006
Posts: 32
Reg assertions i think the above two points are about which one is appropriate and which is not.

Have a glance on the following

1)First point is assertions are not going to be there when the application is deployed.

2)Second one is public methods can be called from anywhere and anytime.
If u use assertions the parameters are not going to be validated at
runtime because Refer point one

3)The lastone is private methods r called from with in a class u can assure
abt the values.

hmmm .....

simply private methods are under our control
whereas public ones r not in our hand.

Hope it is cleared and i don't think extra code is required.

Regards,<br />Naveen<br />SCJP 5 - 83%<br />SCWCD - 84%
marc weber

Joined: Aug 31, 2004
Posts: 11343

Hi Girish, welcome to JavaRanch!

To get better responses in the future, please make your subject lines more descriptive (especially when posting multiple questions on similar topics). Thanks!

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Assertion
It's not a secret anymore!