Okay, I've been hearing rumblings that it's past time to put together an errata list for K&B 6
I'm going to partially pull a 'Tom Sawyer' here - I'll start looking at the notes in my master copy of the book, AND if you guys want to use this thread to add any errata you know of, it'll help speed up the process. (I know, I'm just shameless.)
Thanks for your continued support!
Chapter 3, self test answer 7, line 12 in code, getBidValue should be getValue.
A small change on page 618 will be good, I'm quoting the actual sentence
By saying <? extends Animal>, we're saying, "I can be assigned a collection that is a subtype of List and typed for <Animal> ........."
It would be better if it is
By saying List<? extends Animal>, we're saying, "I can be assigned a collection that is a subtype of List and typed for <Animal> ........."
as the explanation says about List but its not written in the first part.
Another suggestion, chapter 8 self test question 1, option B says
It does not have access to non-static members of the enclosing class
I would say that it should say it does not have DIRECT access to ...... (just a suggestion, I may be pushing it too much)
Another suggestion, chapter 10 page 798, it says
When searching for class files, the java and javac commands don't search the current directory by default
I've seen a few people get confused with this. If we add to it that this happens only if we use the -cp or -classpath flag, that would be great, the context is indeed the -cp/classpath flag so its not wrong, but I've seen a few people get confused with this.
The answer to the 11th question of 10th chapter is wrong (discussed many times like here).
One found in search here
I'll try to come up with some more as I find them...
The class contains these variables:
The hashCode() function is defined as:
The exam claims that the following code (option D) is ok for the equals method:
As far as I can see, if you have, for example, one SortOf object with code="foo", bal=1,rate=2 and another with code="bar",bal=2, rate=1 then their hashcodes are different (3 versus 6) but the equals method would report them as equal (since 3*1*2==3*2*1).
That would be bad.
The code from the answer does not match the code from the original question on page 272. The code on 281 will not compile because of line 12 -- there is no getBidValue() method defined.
Picky, I know, but confusing if you don't go back and look at the original question.
(THANKS FOR THE BOOK!)
On the line #14: name = c.readLine("%s", "input?: ");
should be: String name = c.readLine("%s", "input?: ");
My book has a "." after the "A" as part of the command line that is invoked. None of the answers have a ".", so none of them are correct.
java _ - A .
First of all I must say that your SCJP 6 Study Guide book is great! You managed to explain complex topics with a rare combination of precision and humor. Thanks as lot!
Now the tough part: In chapter 5, section "Legal Expressions for if Statements" (page 333) the examples reported have been very confusing to me. I started to ask myself: "which is the operator precedence among the &&, ||, &, |, !=, and ^ operators?". In your book I could not find any answer. Yet, the topic is important if the student wants to fully understand (and remember) your examples and not fail this topic in the exam. I tried to infer myself the operator precedence based on your examples, and it was hard to figure it out. I could only browse other (online) material to find an answer. Only watching at the operator precedence table in the online Sun Java Tutorials trail (see Equality, Relational, and Conditional Operators section at http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html) I could clearly learn the precedence sequence and fully understand your examples.
It would be probably great if you insert (even a partial section of) the table in your next version of the SCJP guide.
See JavaRanch Naming Policy
Stating this the way it is in the book (that your specifying whether or not the endpoints are exclusive) I would expect that if a boolean value true is passed the endpoint should be exclusive, but instead they are inclusive. This was identified in test problem 11 at the end of chapter where I got the incorrect answer because of the confusion since I study from these tables. But now that I made this post I'm sure I will remember it correctly.
"Keep in mind, then, that the problem of putting the wrong thing into a typed (generic) collection does not show up at the time you actually do the add() to the collection."
The sentence is not accurate for sorted collections. When doing an add() to a sorted collection, such as a TreeSet, the ClassCastException will occur during the add() operation.
The statement would be true if changed to read as below since Lists are not sorted collections.
"Keep in mind, then, that the problem of putting the wrong thing into a typed (generic) List does not show up at the time you actually do the add() to the List."
I would argue that F is a more appropriate answer than E.
Your AccountManager class encapsulates its accountTotals map. Write access to it is limited to:
public void setBalance(String accountName, int amount)
No other code in AccountManager modifies the map values.
So there is no way to get a null value into accountTotals map.
Had the method signature been this instead, I would agree with your answer E:
public void setBalance(String accountName, Integer amount)
The arrow symbol seems to be wrong.
HashSet implements Set but the arrow shows as 'extends'. Similarly for TreeSet and TreeMap (implements NavigableSet and NavigableMap respectively).
Forgive me if this has been reported elsewhere.
Is it possible that there is a typo there? Is it saying a concrete class must declare no subclasses of those declared by the interface method? What does that even mean???
"... a nonabstract implementation class must do the following:
- Provide concrete (nonabstract) implementations for all methods from the declared interface.
- Follow all the rules for legal overrides.
- Declare no checked exceptions on implementation methods other than those declared by the interface method, or subclasses of those declared by the interface method".
Your explanation states the B would be correct if a char was used instead of a String. For B to be correct it would have to look like this:
It is missing the "hello fred" that was output on line 8 of the code.
The answer A is also correct: "It prints X and exits".
Sure, it also prints the Exception to standard error. But A is correct the way it is worded, in addition to G.
For example, on Windows try this (assuming you named your class Ch09Q09):
java Ch09Q09 2> output.err
The console output will be:
The output.err file will contain:
Exception in thread "main" java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
"...and the output is ''false true''; which set(s) of code fragments must be inserted? (Choose all that apply.) "
"...and the output is ''false false''; which set(s) of code fragments must be inserted? (Choose all that apply.) "