An object in Java may contain a small amount or a large amount of memory - it depends almost entirely on what you store in it. For example, a String is an object. Now, you can have a String that contains 10 characters - that object will contain 20 bytes (2 bytes per character - characters are stored as Unicode), plus a small amount of overhead. The amount of overhead may vary, depending on the specific Java implementation. Another String, which contains 100 million characters, will be stored using 200 million bytes (plus a small amount of overhead).
I believe the JVM may also round the space used up by an object up - for example, to the closest power of two. But once again, this is implementation-specific.
Chat with our AI personalities
To instantiate a object, we use the new keyword in Java, which creates an object in memory.
see http://www.javamex.com/tutorials/memory/object_memory_usage.shtml
No, there is no such operator or function in Java that can tell you the amount of memory an object uses.
GC stands for garbage collector - this is the mechanism which cleans up unused object references. The GC is why memory management in Java is almost non-existent.
Java does not have a sizeOf() operator and hence there is no way we can actually determine the size of a java class object. However we can analyze the overall heap space utilization to try to get an approximate indication of how much memory is used by an object but it is not accurate.