File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Size of a Class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Size of a Class." Watch "Size of a Class." New topic

Size of a Class.

Vijay Sharma

Joined: Oct 12, 2005
Posts: 17

class a
// some statements.


There is a class "a" with some statements. If i want to find the size of the class, is there any function in Java?

Please help me out with this.

Cheers,<br />Vijay Sharma
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
What exactly do you mean by "size of the class"? Why do you need to know it?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
Hi Vijay ,

No there is no way you can find the size of the object of any class(if u are refering that).It's not specified by the Java VM specification or the Java Language specification.

[ April 20, 2006: Message edited by: faisal usmani ]
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Um, there are several possible ways to interpret this, and before we try to discuss them all, I think it would be better to get an answer to Ilja's question. Size in bytes of the class in memory? Size in bytes of the class file? Size in bytes of the source file? Number of lines of code in the source file? Some other metric? The question is far too vague right now.

"I'm not back." - Bill Harding, Twister
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
well i know that you could debug, and maybe there is a way to count as

the debugger goes from line to line, if you mean length of code in the



You down with OOP? Yeah you know me!
I agree. Here's the link:
subject: Size of a Class.
It's not a secret anymore!