aspose file tools
The moose likes Beginning Java and the fly likes Plz . Answer Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Plz . Answer" Watch "Plz . Answer" New topic
Author

Plz . Answer

faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
What is the size of an object in Java , if the class has no member variables or member functions .

Eg :-

class ABC
{

}

What will be the size of object of class ABC if we do

ABC ob1 = new ABC();


Do we have a sizeof operator in Java as we have in C/C++
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

The actual amount of memory that an object uses depends on the Java implementation -- i.e., it's not specified by the Java VM specification or the Java Language specification. The number is never directly useful in any program -- no Java language function or construct depends on the memory image size of an object. The precise answer may well vary by JVM vendor, by platform, and even by version.

That said, for Sun's JVMs a good rule of thumb is 16 bytes for an object, plus four bytes for each member -- except doubles and longs, which are 8 bytes each.

Note: have a look at this when you have time.


[Jess in Action][AskingGoodQuestions]
faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
Thanks sir
I got the point
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Plz . Answer
 
Similar Threads
protected member access
How to know a class is Immutable or Not
Mughal Mock Exam Doubt.
Beginner in servlets
Are my answers correct ?