This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Errata to errata of SCJP study guide by K. Sierra & BB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Errata to errata of SCJP study guide by K. Sierra & BB" Watch "Errata to errata of SCJP study guide by K. Sierra & BB" New topic
Author

Errata to errata of SCJP study guide by K. Sierra & BB

John Brown
Ranch Hand

Joined: Dec 01, 2004
Posts: 35
The errata says that:


Page 505,Second paragraph

Change:
.. method has finished, you can't say t.start(); you'll get a big fat runtime exception.

To:
.. method has finished, calling t.start() won't restart it.


But we know that the 1.4.2 API states that start() throws IllegalThreadStateException - if the thread was already started.
So the errata is wrong, isn't it?
See also this topic Thread Q from Sierra & Bates SCJP Study Guide.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Well, if you get a runtime exception, t.start() won't restart the thread. It seems like both statements are correct to me.

Layne


Java API Documentation
The Java Tutorial
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
If I remember correctly, for Java 1.4, calling start() on a thread which had finished its run() method did not cause the exception to be thrown. The exception was only thrown if the thread could be still executing run() while start() was called a second time. That's why the statement was changed in the errata.

In Java 5.0 it appears that the exception is now thrown when calling start() on such a "dead" thread.
[ January 23, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
John Brown
Ranch Hand

Joined: Dec 01, 2004
Posts: 35
Thanks for the answers.

Layne, if the phrase "you'll get a big fat runtime exception" is true, why was it eliminated via the errata? I thought the errata was supposed to correct things which weren't right ?

Barry, you remember correctly, for Java 1.4, calling start() on a thread which had finished its run() method does not cause the exception to be thrown, the exception is only thrown if the thread is still executing run() while start() is called a second time.

But according to the API, this behaviour is wrong:

public void start()[...] Throws: IllegalThreadStateException - if the thread was already started.


Now, if the thread is dead, that means it was already started, isn't it? So if the thread is dead (it's run() method has finished), then calling start() on this dead thread should throw an IllegalThreadStateException, right?
John Brown
Ranch Hand

Joined: Dec 01, 2004
Posts: 35
Page 536:
If start() is called more than once on a Thread object, it will throw a RuntimeException.


This is in agreement with the API. But the errata is not.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Yes. Unfortunately the reality is that some (maybe all?) Sun JDKs prior to JDK 5 did not obey the spec in this regard. Which makes this a poor test question unfortunately, though it's not the author's fault so much as tbe fault of some unknown Sun programmers(s). Anyway, the way I read the errata, "calling t.start() won't restart it" is a true statement, which is intentionally ambiguous about exactly how & why the thread won't restart. Maybe start() will throw an exception (as per the spec), or maybe start() will just return immediately with no effect (as per the buggy reality in JDK 1.4).

Errata are often written under the constraint that the replacement text cannot change the page numbering of the other text. Because the author and publisher are typically trying to just make small modifications that can go into the next printing of the book, without having to re-index the rest of the book. In this case, it would've taken somewhat more space to fully discuss the fact that the spec and implementation give contradictory results. And so I'm guessing K&B thought it was more appropriate to give a short vague-but-true answer to replace the previous answer which is specific-but-false under existing JDKs.
[ February 01, 2006: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8801
    
    5
Jim's my hero!


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

Joined: Aug 22, 2005
Posts: 193
I think there needs to be an errata for the link to the errata in the first post of this thread. :-) The link is to errata for things that were detected and fixed in 2003!

Anyone have the link to the new errata? I actually have a couple of items that I've found in my copy of the book and want to see if anyone else has discovered them.

Thanks,
Josh


Rational Pi Blog - Java, SCJP, Dev Bits- http://rationalpi.wordpress.com
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8801
    
    5
Hey Joshua -

We'll be posting a link to the Java 5 errata page in a few days,
John Brown
Ranch Hand

Joined: Dec 01, 2004
Posts: 35
Hi Jim, thanks for your answer.
Yes I agree (always had) that the phrase "calling t.start() won't restart it" is a true statement, I was just confused about the reason the errata was striking the phrase "you'll get a big fat runtime exception", and the errata does that only for the 505 page, and not for the 536 and 508 pages.

So, if I get a question on this topic on the exam, what's the answer? is an exception thrown or not? I would be inclined to answer that with a yes.
[ February 02, 2006: Message edited by: John Bran ]
Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
Thanks Bert.

Josh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Errata to errata of SCJP study guide by K. Sierra & BB
 
Similar Threads
SCJP Mock Tests
K&B Threads: subtle detail calling start() important?
S & B SCJP for Java 5 Study Guide Errata?
SCJP 5.0
SCJP 5.0