Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about Self Test Chapter 6, Question 13 (CH6Q13, K&B7)

 
nick woodward
Ranch Hand
Posts: 370
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More of a suggestion than an error:

page 370, question 13:

Doesn't the question allow you to mistake a stackoverflowerror for a runtime exception and still get the correct answer (B, E)? Just might be easy to miss when marking your work (that's if I'm not mistaken!)

(This post originated in the K&B7 errata thread)
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nick woodward wrote:Doesn't the question allow you to mistake a stackoverflowerror for a runtime exception and still get the correct answer (B, E)?

I think you are correct on this one. If you think StackOverflowError is a runtime exception (or even a checked exception), you could still get the correct answer for this question. If you decide not to execute this code snippet and only check the correct answers (and not the explanation), you'll have a wrong understanding of the StackOverflowError class. But I think it's reasonable to assume readers of a study guide will (or should) read the explanation as well (which clearly states StackOverflowError IS-A Error and IS-NOT-A Exception).

I don't think many improvements can be made to this question to avoid this mistake. Probably the only one I can think of:
1/ change "ouch" to "error" (in fragment II) and to "exception" (in fragment III)
2/ add these two new answer options:
  • G. error is in the output
  • H. exception is in the output

  • After these changes the correct answers would be B, E, and G. And someone who thinks StackOverflowError is a runtime (or checked) exception will select B, E, and H (which is clearly wrong).

    Hope it helps!
    Kind regards,
    Roel
     
    nick woodward
    Ranch Hand
    Posts: 370
    11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i (embarrassingly) thought it was a runtime exception, and (luckily) thought it was worth double checking despite getting the correct result.

    definitely like the G/H additions though. personally, having made the mistake myself, I think it's worth being in the errata purely from the perspective that it can easily mislead those that don't know the answer. ie, if i knew the answer i wouldn't fall into the trap, if i didn't, i (most likely) would

    also, it turns out i have to reread overriding and exceptions again. sigh.
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    nick woodward wrote:i (embarrassingly) thought it was a runtime exception, and (luckily) thought it was worth double checking despite getting the correct result.

    That's very strange! The Java API is well and consistently named. So StackOverflowError already reveals it's an error and not a (runtime) exception; if it was, it had been StackOverflowException instead. I can only think of 1 or 2 incosistenties in the Java API. There's a Hashtable class which should actually have been HashTable instead to be consistent with other classes. In Java you don't have pointers, but references; so NullReferenceException would probably have been slightly better than NullPointerException. Based on the camelCase notation, you might expect the instanceof operator to have an upper case O instead of a lower case o; but Java keywords are always lower case so that's not an issue at all

    nick woodward wrote:definitely like the G/H additions though. personally, having made the mistake myself, I think it's worth being in the errata purely from the perspective that it can easily mislead those that don't know the answer. ie, if i knew the answer i wouldn't fall into the trap, if i didn't, i (most likely) would

    I'll add it to the errata overview as a possible improvement of this question.
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Roel De Nijs wrote:I'll add it to the errata overview as a possible improvement of this question.

    Added to the errata overview.
     
    nick woodward
    Ranch Hand
    Posts: 370
    11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks.

    i agree that stackoverflowerror is well named, but if you can't remember the exact name.....

    looking back, stackoverflowexception sounds ridiculous, but still.....!
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    nick woodward wrote:i agree that stackoverflowerror is well named, but if you can't remember the exact name.....

    So let's think about what you can do to never forget it...



    Still thinking...



    Aha! I have a brilliant idea:
    1. Take an empty paper tray which can hold at least 250 A4-sized pages.
    2. Take an A4-sized page and start writing StackOverflowError (with the appropriate case of course) until the page (back and forth) is completely full.
    3. Once a page is full, put the page in the paper tray
    4. Repeat steps 2 and 3 until adding another full page to the paper tray would result in a StackOverflowError
     
    nick woodward
    Ranch Hand
    Posts: 370
    11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Roel De Nijs wrote:
    nick woodward wrote:i agree that stackoverflowerror is well named, but if you can't remember the exact name.....

    So let's think about what you can do to never forget it...



    Still thinking...



    Aha! I have a brilliant idea:
    1. Take an empty paper tray which can hold at least 250 A4-sized pages.
    2. Take an A4-sized page and start writing StackOverflowError (with the appropriate case of course) until the page (back and forth) is completely full.
    3. Once a page is full, put the page in the paper tray
    4. Repeat steps 2 and 3 until adding another full page to the paper tray would result in a StackOverflowError


    the mistake is taped to my wall on an A4 sheet with a few other exceptions.....

    close enough!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic