You mean the number of bytes that an object takes up in memory?
There's no way to find that out in the standard Java API. Java does not have a "sizeof" operator, like you have in C and C++.
Note that the size of an object in memory depends on the particular implementation of the JVM you are using. It might be different for the Sun JVM on Windows and the HP JVM on HP-UX, for example.
If you really are desperate to find this out in your Java application, I think there is a way to find out how many bytes an object takes up via the debugger API, but that API is not easy to use.
How can objects have predefined size as it really depends on the number and type of instance variable it holds. [ August 23, 2006: Message edited by: Ela Jha ]
Ankur Sharma
Ranch Hand
Joined: Dec 27, 2005
Posts: 1234
posted
0
Originally posted by saikrishna cinux: can anyone tell me the size of an object as premitives got the size why dont objects have some constant value(size)?
Dear Saikrishna,
You can use the code below:
Here is the Interpreter class :
Now you compile both class and try to run like following
Hope this helps you out.
The Best way to predict your future is to create it
Ankur Sharma