This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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 ?
 
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.
 
Sheriff
Posts: 21288
87
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"):
 
lowercase baba
Bartender
Posts: 12613
50
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.
 
Java Cowboy
Sheriff
Posts: 16082
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!