File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes list the objects of particular class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "list the objects of particular class." Watch "list the objects of particular class." New topic
Author

list the objects of particular class.

sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

hi all i have some doubts:
1)can we get a list of objects that are presently in memory by passing full class name?
2)can we list classes that are loaded into memory.

thanks,
Sudheer.K


Sudheer
SCWCD, SCJP 5
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7052
    
  16

sudheer kiran wrote:1)can we get a list of objects that are presently in memory by passing full class name?
2)can we list classes that are loaded into memory.

As far as I know: no - except maybe on a case by case basis - however, you might be able to get some of that information from a profiler.

My question is: Why do you think you need to know this? Java is not C/C++, so memory management is not your concern. And you absolutely should not write programs that rely on that information, or any pattern derived from it, as the memory model may change in the future. I've never needed anything like it in 10 years of using Java.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

If you really want to do this, then it might be possible by using the JVM's debugger API, but that means you're actually writing a debugger for Java programs, which is not a very easy task. There are not some easy to use methods you can call to list all instances of a particular class in the current JVM.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

hi thanks for the replies. i just wanted to know if any API is available for quick usage.
i haven't come across a situation but thought of to know if is it possible.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: list the objects of particular class.
 
Similar Threads
Generics compendium
memory allocation problem
Tree Data Structure
can we force Garbare collector
Getting classes in a package programatically