The other way instead of using the sizeof() operator which Java doesnot support you can do the following:
static Runtime rt = Runtime.getRuntime();
long begin, finish;
begin = rt.freememory();
O = new Object();
finish = rt.freememory();
System.out.println("This had taken " + (begin-finish) + "bytes.");
This method although has a short coming that a garbage collection could occur in the middle of the code which you are instrumenting. This will throw off the byte count.