How can we find size of the object ?
Answers were Sorted based on User's Feedback
there is no sizeOf() in java to find the size of the object
| Is This Answer Correct ? | 8 Yes | 4 No |
Answer / lachha g
you can use Instrumentation class.
use long getObjectSize(Object objectToSize) method.
It returns amount of storage consumed by the specified object.
package Test;
import java.lang.instrument.Instrumentation;
public class ObjectSize {
private int x;
private int y;
ObjectSize(int x, int y){
this.x=x;
this.y=y;
}
public static void main(String [] args) {
ObjectSize obj= new ObjectSize(2,4);
System.out.println(Test.getObjectSize(obj));
}
}
class Test {
private static Instrumentation instrumentation;
public static void premain(String args, Instrumentation inst) {
instrumentation = inst;
}
public static long getObjectSize(Object o) {
return instrumentation.getObjectSize(o);
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / suvarna
getObjectSize(Object objectToSize)
Returns an implementation-specific approximation
of the amount of storage consumed by the specified object.
| Is This Answer Correct ? | 0 Yes | 3 No |
What are parsers? Dom vs sax parser.
What is data structure in java?
What class is used to implement a Throwable array?
What is token in java?
What is HashTable?
What is == in java?
What is this keyword in java?
What is a byte array?
1.what is the exact difference between applet and frame? 2.Do we use main method in frames?
What is Yield() method when we r using this ? tell exactly
How do you use, call, and access a non-static method in Java?
What is the USE of Null interfaces ??...if thers nothing inside these interfaces how are they used and WHy are they used ???? No 1 has given a proper description yet