This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to print the name of an object in java ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How to print the name of an object in java ?" Watch "How to print the name of an object in java ?" New topic
Author

How to print the name of an object in java ?

PrachiS Shah
Greenhorn

Joined: Sep 02, 2010
Posts: 10
how to print the name of an object in java ?

for eg.
String start = "hello";

Now how to print the name of the object ?
sharad koshal
Greenhorn

Joined: Sep 06, 2010
Posts: 4
good question.even i am getting confused
.experts please come in.
please help us out.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19232

You can't; the variable name isn't stored with the object. Furthermore, any object can have multiple references ("names"):


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10043
    
    6

Further, the variable name is really only useful to someone looking at the source code. It's a way for us HUMANS to identify thing in the code.

When the program is compiled and being run, the JVM or OS can really use whatever name it wants.


Never ascribe to malice that which can be adequately explained by stupidity.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12953
    
    3

Objects do not have names - variables have names. But a variable is not the same as the object that it refers to. As Rob shows, you can have multiple variables that refer to the same object.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to print the name of an object in java ?
 
Similar Threads
Printing a Hashmap
compiler error regarding method
Applet Problems
about thread synchronization
How to select a tray in java print service?