Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes Output difference why? 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 » Java » Beginning Java
Bookmark "Output difference why?" Watch "Output difference why?" New topic

Output difference why?

abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

In the first example, you are creating a new Thread object (line 6) and then you print out the name of that object on line 8. Note that line 7 does nothing: you call the currentThread() method but you're not doing anything with the return value, so nothing happens.

In the second example, you get the current (existing) Thread object, which is the thread that the main() method runs in, and you print its name.

The two pieces of code are not doing the same thing. Did you expect them to give the same output?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
It is sorta covered in the JavaRanch Style Guide.
subject: Output difference why?
Similar Threads
Thread question
What causes InterruptedException? How to recover?
Basics of Thread and Synchronization
wait() is block object pls help