• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to print the name of an object in java ?  RSS feed

 
PrachiS Shah
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good question.even i am getting confused
.experts please come in.
please help us out.
 
Rob Spoor
Sheriff
Posts: 21117
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't; the variable name isn't stored with the object. Furthermore, any object can have multiple references ("names"):
 
fred rosenberger
lowercase baba
Bartender
Posts: 12559
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16047
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!