• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

q on Thread from mock exam

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
5. What is the Thread output?

A) Executing the myTest() method
Executing run() method
B) Executing run() method
Executing the myTest() method
C) No output
D) Compile time error
The answer they give is A)
Could some explain why and, more important if that anytime the
output is A)?
I ran the code with an IDE with Debug and the output was anytime B)
how this happens?
thanks in advance
rgds,
cristi
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each JVM vendor implements Thread differently. When I ran your code I always get answer A. However, when I add "for (int i = 0; i <= 1000000; i++);" after line "t.start();", I get answer B.
I believe that the correct answer should be A and B.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cristi, Zheng ...
The SCJP Exam expects you to understand what will happen when code is compiled from the command line using JDK 1.2.
When studying, it is safest to only use Sun's JDK; IDE's often add code or implement the JVM differently.
Jane
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Sun JDK 1.2.1. I get this output: -
Executing the myTest() method
Executing run() method
So the answer should be A
 
Raj Mehra
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This program under Sun JDK 1.2.1. outputs: -
null
Executing run() method
a
Executing the myTest() method

[This message has been edited by Raj Mehra (edited January 14, 2001).]
 
Cristi Tudose
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jane,
What you say is perfectly right about the exam.
But,why is this order and not B ?
Am I missing something ?
best rgds,
cristi

Originally posted by Jane Griscti:
Hi Cristi, Zheng ...
The SCJP Exam expects you to understand what will happen when code is compiled from the command line using JDK 1.2.
When studying, it is safest to only use Sun's JDK; IDE's often add code or implement the JVM differently.
Jane


 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See cross post http://www.javaranch.com/ubb/Forum35/HTML/000139.html in Mock Exam Errata forum.
Closing this thread.
Jane
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic