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 exception handling ?? 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 "exception handling ??" Watch "exception handling ??" New topic

exception handling ??

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
The following method is designed to convert an input string to a
floating point number while detecting a bad format.
[3] [I think factor must have been declared as float member variable
or something]

Which of the following descriptions of the results of various inputs to the method are correct?
(a)Input = �0.234� � Result: factor = 0.234, �Finally� is printed, true is returned.
(b)Input = �0.234� � Result: factor = 0.234, �Finally� is printed, false is returned.
(c)Input = null � Result: factor = NaN, �Finally� is printed, false is returned.
(d)Input = null � Result: factor = unchanged, �Finally� is printed, NullPointerException is thrown.

frnds ,
option a is correct ..that is fine ...i cannot understand why opition is correct ...specifically factor = unchanged i didnt get

can anyone clarify it

[ October 13, 2005: Message edited by: Barry Gaunt ]

Thanks & Regards<br /> <br />-Srikanth
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
Originally posted by srikanth reddy:

(d)Input = null � Result: factor = unchanged, �Finally� is printed, NullPointerException is thrown.

Its simple
factor = Float.valueOf(s).floatValue();
In this statement the exception occurs while performing Float.valueOf(s) ie. before calculating .floatValue() and before assigning the calculated value to the variable factor. As soon as the exception occurs control jumps to the corresponding exception handler withoug assigning anything to factor.
hence factor remain unchanged.

Hope it helps

Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
I agree. Here's the link:
subject: exception handling ??
It's not a secret anymore!