Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

String and stringbuffer both represent string objects. Can we compare string and stringbuffer in java?

922


Define inheritance?

962


What is binary tree in java?

999


What is the difference between import java.util.date and java .util?

1002


What ide should I use for java?

955


How does java enable high performance?

1088


What is difference between iterator and enumeration in java?

940


What is an empirical question?

912


Can a java program have 2 main methods?

997


Write the algorithm to check the number non-leaf nodes in a tree.

1008


Define Multiprogramming and Multiprocessing in java.

1062


What are the two ways to create a thread?

948


How do you call a reference in java?

911


What is functional interface in javatpoint?

972


what is the difference between Object Based Language and Object Oriented Language?

969