This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A hard question 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 "A hard question" Watch "A hard question" New topic

A hard question

Adil El mouden
Ranch Hand

Joined: Jun 01, 2005
Posts: 82
Another question related to join method:

Select the two correct answers.

1 The first number printed is 13.

2 The number 14 is printed before the number 22.

3 The number 24 is printed before the number 21.

4 The last number printed is 12.

5 The number 11 is printed before the number 23.

A: 2 and 4
Thank you
[ July 19, 2005: Message edited by: Barry Gaunt ]

SCWCD 1.4(Loading...), SCJP 1.4(98%), Bachelor of Engineering (computer science)
Devender Thareja
Ranch Hand

Joined: Jul 14, 2005
Posts: 187
Originally posted by John Edwin:

public class Joining {
static Thread createThread(final int i, final Thread t1) {
Thread t2 = new Thread() {
public void run() {
try {
} catch (InterruptedException e) {
return t2;

public static void main(String[] args) {
createThread(10, createThread(20, Thread.currentThread()));

You see, the currentThread (main thread) is being passed to the createThread method.
Inside createThred method a new thread t2 is created.
The run method of t2 is implemented such as it waits for thread t1 to finish, because of t1.join statement.
The t1 actually is main thread.
T2 will finish last, always.
The last print statement in T2 is 12.

Hope it helps.

Devender Thareja
Byron Foo

Joined: Jul 20, 2005
Posts: 4
a good question:

I think the sequence should be like this:
23 -> (21->14 or 14->21) -> 13 -> (11->14 or 14->11) -> 22 -> 12
Rupak Khurana
Ranch Hand

Joined: Mar 01, 2005
Posts: 89
I dont think Thread.join() is covered in SCJP exam. Am I wrong ?

SCJP 1.5<br />SCWCD 1.4
I agree. Here's the link:
subject: A hard question
Similar Threads
Thread question
Can some one explain in detail what actually is happening at Stack level on this set of code.
join() in threads
Threading related question from khalid mughal's book
output of this program from certification book