You can serialize things in Java, too. Your google keywords are "java serialization tutorial". Send your output to a ByteArrayOutputStream.
I'm not convinced that it's a useful technique for finding the memory usage of objects, but the Java concept is pretty much identical to the C# code you posted there.
Many app servers have a mechanism for determining such statistics as well, although getting aggregate data across replicated servers could be tricky (I've never tried).
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop