aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes nit w/ chap.6 q.13 S&B 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 "nit w/ chap.6 q.13 S&B" Watch "nit w/ chap.6 q.13 S&B" New topic
Author

nit w/ chap.6 q.13 S&B

Steven Elliott
Greenhorn

Joined: Mar 28, 2002
Posts: 14
Somehow this ended up on Java Porch forum. Reposting here where I thought it I had posted it originally.

Sierra & Bates SCJP 6 chap. 6, question 13 is:


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.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi Steven,

It could be a valid nit or not

The best way to know for sure is to post the entire question, with all the answers and explanations.

Thanks,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Dear Steven,

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



HTH,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Steven Elliott
Greenhorn

Joined: Mar 28, 2002
Posts: 14
Here is the complete question 13 from Chap. 6 S&B

@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.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi Steven,

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.

Thanks,

Bert
Steven Elliott
Greenhorn

Joined: Mar 28, 2002
Posts: 14
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".
Joey Sanchez
Ranch Hand

Joined: Jun 23, 2011
Posts: 86



I don't understand why the first print line is 987.12346, what happened with the number 5?

Could someone explain this?

Thanks in advance!
Mansi Agarwal
Ranch Hand

Joined: Apr 11, 2012
Posts: 53
Yes Joey!!

Actually we are setting the Maximum Fraction Digit to 5 so it is will print just 5 digits after the decimal.
To do so it round off the last digits..

I hope you understand!!
Joey Sanchez
Ranch Hand

Joined: Jun 23, 2011
Posts: 86

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.
Joey Sanchez
Ranch Hand

Joined: Jun 23, 2011
Posts: 86

I think I found it

Yalvin Duha
Ranch Hand

Joined: Apr 07, 2012
Posts: 40

Joey Sanchez wrote:

I don't understand why the first print line is 987.12346, what happened with the number 5?

Could someone explain this?

Thanks in advance!

I touched on this before but no one has given a definitive answer as to which methods we are supposed to watch for when it comes to rounding off.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nit w/ chap.6 q.13 S&B