wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Questions on Thread and Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Questions on Thread and Exception" Watch "Questions on Thread and Exception" New topic
Author

Questions on Thread and Exception

Eric Pu
Greenhorn

Joined: Jul 27, 2002
Posts: 23
I don't know the answers to these questions below.
And these questions are discussed again and again in many China JAVA forums,but no one can give the accurate answer and persuade others to believe his/her answer.

Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A. Calling the yield method.
B. Calling the wait method on an object.
C. Calling the notify method on an object.
D. Calling the notifyAll method on an object.
E. Calling the start method on another Thread object.
Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A. Existing from a synchronized block.
B. Calling the wait method on an object.
C. Calling notify method on an object.
D. Calling read method on an InputStream object.
E. Calling the SetPriority method on a Thread object.
Which statement is true?
A. The Error class is a untimeException.
B. No exceptions are subclasses of Error.
C. Any statement that may throw an Error must be enclosed in a try block.
D. Any statement that may throw an Exception must be enclosed in a try block.
E. Any statement that may thro a runtimeException must be enclosed in a try block.

I hope someone here can give us a right answer. Thank you.


SCJP, SCMAD, MCAD<br /> <br />Shanghai,China GMT+0800
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Let's take the third first
Which statement is true?
A. The Error class is a untimeException.
B. No exceptions are subclasses of Error.
C. Any statement that may throw an Error must be enclosed in a try block.
D. Any statement that may throw an Exception must be enclosed in a try block.
E. Any statement that may throw a RuntimeException must be enclosed in a try block.

A. False. Error is a subclass of Throwable. (JLS 11.5 The Exception Hierarchy)
B. True. All exceptions are subclasses of the Exception class. (JLS 11.5 The Exception Hierarchy)
C. False. (JLS 11.3 Handling of an Exception)
D. True. Only checked exception (subclasses of Exception without subclasses of RuntimeException) are required to be handled by the programmer.(JLS 11.3 Handling of an Exception)
E. False. Unchecked exceptions (subclasses of RuntimeException) are not required to be handled. (JLS 11.3 Handling of an Exception)
The answer of D (true) is questionable since subclasses or RuntimeException are also subclasses of Exception but they do not need to be handled.
Side note: The question should be "Which statements are true?" since there are two correct answers.
[ August 07, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Eric Pu
Greenhorn

Joined: Jul 27, 2002
Posts: 23
I have two mock tests that both have the third question.
One says B is the correct answer,but the other says D is.
I am puzzled by the two papers.
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Hi Eric, B is easily settled to be true. For D, you can try testing it with code to resolve your doubts.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A. Calling the yield method.

It could cause a thread to stop executing depending on the priorities of the other threads. I don't know if that is to be considered direct enough for the person who wrote the question. Bad worded question.
B. Calling the wait method on an object.
It would definitely pause the thread.
C. Calling the notify method on an object.
It won't stop the thread.
D. Calling the notifyAll method on an object.
It won't stop the thread.
E. Calling the start method on another Thread object.
It won't stop the thread.

Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A. Existing from a synchronized block.

It cannot
B. Calling the wait method on an object.[/i.]
It can.
[i]C. Calling notify method on an object.

It cannot.
D. Calling read method on an InputStream object.
It can if no bytes are available.
E. Calling the SetPriority method on a Thread object.
It cannot.
Considerations:
If any Throwable is thrown and not caught the thread is stopped.
Depending on the scheduling algorithm if a newly started/waken up thread has a greater priority than other, the second would pause for the other to complete.
Should we consider these? Specially in the thread area very ambigous questions are possible.

Which statement is true?
A. The Error class is a RuntimeException.

No it isn't. However it exibits the same behaviour regarding the compiler won't force you to either declare it or catch it.
B. No exceptions are subclasses of Error.
true
C. Any statement that may throw an Error must be enclosed in a try block.
false
D. Any statement that may throw an Exception must be enclosed in a try block.
true for all except RuntimeException
E. Any statement that may thro a runtimeException must be enclosed in a try block.
false


SCJP2. Please Indent your code using UBB Code
David Poglitsch
Greenhorn

Joined: Jul 26, 2002
Posts: 16
On question #3, I thought that
D. Any statement that may throw an Exception MUST be enclosed in a try block

was False.
If the class or method containing the statement was qualified with "throws Exception", then wouldn't the try block be unnecessary (e.g. not a MUST situation)?
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
You are right David, but only methods and constructors can accept throws
Eric Pu
Greenhorn

Joined: Jul 27, 2002
Posts: 23
I took the 1.2 test this morning and got 94%.
Thanks to everyone here. You have given me confidence.
Also, I encountered a question that was quite similar to the one I asked yesterday .
[EXAM QUESTION REMOVED BY VALENTIN]
Please do not post real exam question and read Position on Real Questions - Must Read!


I chose A & C in the test and got right.
So I think maybe Sun think E is wrong.
Thank again!
payaqa(Eric PU)
Shanghai, China
7:00 GMT Aug 8,2002
[ August 08, 2002: Message edited by: Eric Pu ]
[ August 08, 2002: Message edited by: Eric Pu ]
[ August 08, 2002: Message edited by: Valentin Crettaz ]
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Hi Eric. Congratulations on a very good score!!
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Calling the start method on another thread could indeed stop your thread, if the processor or operating system decides it would rather give priority to the new thread. This is implementation-dependent.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
And similarly, depending on implementation, changing the priority of another thread could cause yours to stop.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
By the way, the question about errors and runtime exceptions looks very similar to one that was on my real exam two days ago. It may even be identical.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Questions on Thread and Exception
 
Similar Threads
stoping the thread
question about thread
Thread
mock question -regd
Thread Doubt