How can we find size of the object ?
Answer Posted / 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 |
Post New Answer View All Answers
What is the purpose of a default constructor?
What are the two categories of data types in the java programming language?
What is the purpose of methodology?
How can you say java is object oriented?
What are three ways in which a thread can enter the waiting state in java programming?
Explain the key functions of data binding?
What is this keyword in java?
What is boolean query?
What is difference between static variable and global variable?
When arithmeticexception is thrown?
What is an example of procedure?
Java is pass by value or pass by reference? Explain
How is hashset defined in java?
Is null keyword in java?
What are static methods?