aspose file tools*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
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: 19760
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11476
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14345
    
  22

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 8 API documentation
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to print the name of an object in java ?