How do I print the variable name holding my object?
For example, I have:
myclass ob=new myclass()
How would I print \"ob\"?
Slightly more complete (but essentially the same as above):
object.getClass().getName() will give you the fully qualified name of the object (i.e.package.className. For example, String thing = new String(); thing.getClass().getName() will return "java.lang.String".
className.class.getName() will give you the fully qualified name of the object (i.e.package.className. For example. String.class.getName() will return "java.lang.String".
Print it how ever you want. Perhaps using System.out.println().
The name of the variable is compile time information that is not typically stored after compilation. The variable name is stored if you compile with debugging information.
In mamy contexts, it is a ridiculous request to want to print the name of a variable, but if you really need to do that, read up on java debugging information.