This week's book giveaway is in the Other Open Source APIs forum. We're giving away four copies of Storm Applied and have Sean Allen, Peter Pathirana & Matthew Jankowski on-line! See this thread for details.
One of the correct answers is:
G. The invocation of parse() must be placed within a try/catch block
My nit is you can declare to throw an Exception in the main method so "...must be placed within a try/catch block." is not true because it is not the only option. I would be upset if I had missed this by not marking this as a correct answer because the way it is worded.
Please post the full question and other options as well. In my opinion, this is the correct answer may be because parse() method
throws a checked exception. As main is the last thread where such things can be handled, it is better to catch it and handle it. Else
it will blow up your program. So it is better that we don't say something like
@Prithvi: I agree that throwing an Exception in main() is not usual nevertheless doing so allows the program to compile and run as normally as you would expect. Moreover had this been any other method there would be no question that declaring the Exception would be a valid option (rule "handle-or-declare") as is the case for all checked exceptions.
Joined: Oct 14, 2002
I agree that instead of saying "try/catch" we should have said something like "handled or declared". We'll note that in our list of fixes - thanks.
As far as the real exam goes, remember that you'll ALWAYS be told how many correct answers there are, so in the event that you spot something like this (which I don't think you will), knowing the number of correct answers would help you out.
Joined: Mar 28, 2002
Hey thank you Bert. Your book has been a great help and as you note knowing the number of correct answers will be a clue as to "which is/are the most correct".
Hi Mansi Agarwal,
As you say, the result would be 987.12345 instead of 987.12346 with five digits after de dot.
How does it work the round off(¿if x>5 then +1 the previous digit? else?)? Does it appear in the api?
Method definition: setMaximumFractionDigits
public void setMaximumFractionDigits(int newValue)
Sets the maximum number of digits allowed in the fraction portion of a number. maximumFractionDigits must be >= minimumFractionDigits. If the new value for maximumFractionDigits is less than the current value of minimumFractionDigits, then minimumFractionDigits will also be set to the new value.
Parameters: newValue - the maximum number of fraction digits to be shown; if less than zero, then zero is used. The concrete subclass may enforce an upper limit to this value appropriate to the numeric type being formatted.