This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
No there isn't. There are some tricks you can use to determine the size of an object (for example see this rather dated article. But they are not things you would want to do in production code. It's more for the initial development work.
You can also use profilers to look at the size of objects.
Take a look at this google search for more discussion on the subject, as it is a frequently asked question.
July 8th, 2008: JDK 6 Update 7 with Java VisualVM released. Starting from JDK 6 Update 7, VisualVM is also available as a JDK tool called Java VisualVM. This way you will get a stable tool tested with respective JDK distribution. Latest Sun JDK 6 update can be downloaded here.
There is no API provided to find the size of an object......
but there is an alternative way to find the size of as object
its in Runtimeclass in lang package....
Runtime obj = Runtime.getRuntime();
System.out.println(obj.totalMemory() - obj.freeMemory());
which gives you the size of an Object