• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to print the name of an object in java ?

 
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
Pie
Posts: 20512
54
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
Pie
Posts: 12100
30
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
Saloon Keeper
Posts: 15216
36
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic