I am trying to find the number of objects and name of the objects of a class dynamically using java reflection API but I am not able to get the object names. Instead of object names, I am getting only the class name that I pass. Could anyone help me out in this regard? Any help is appreciated.
As Ernest already said, objects don't have names. Perhaps you mean the name of a variable that contains a reference to an object, but if you do this is far from advanced Java. It's a rather elementary confusion.
You mean the name of a variable pointing to an object? Note that an object can have any number of variables pointing to it, so even if the JVM did track this, the "names" wouldn't be unique. But they're not tracked. There's no notion of the "name" of an object in Java.
In addition, you can't get the number of objects using anything in the standard API; you have to run the JVM in debug mode and use the debugger API to get that information. Otherwise, you can add a static member to count the instances of a class, and increment it in the constructor of that class. But nothing in the reflection API will tell you this.