Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertion" Watch "Assertion" New topic
Author

Assertion

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
Sheriff

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
sscce.org
 
jQuery in Action, 2nd edition
 
subject: Assertion
 
Similar Threads
why ?A assertion question.
assertions
Regarding Assert
Dan's test ques - Assertions