A Java object is an instance of a class or an array. Every object instance in a Java program occupies some memory. The manner in which a Java object is represented in memory is left up to the implementor of the Java virtual machine and can vary from one implementation to another. However, in the typical Java virtual machine, a object data occupy contiguous memory locations.
The region of memory in which objects are allocated dynamically is often called a heap . In Chapter we consider heaps and heap-ordered trees in the context of priority queue implementations. Unfortunately, the only thing that the heaps of Chapter and the heap considered here have in common is the name. While it may be possible to use a heap (in the sense of Definition ) to manage a region of memory, typical implementations do not. In this context the technical meaning of the term heap is closer to its dictionary definition--``a pile of many things.''
The amount of memory required to represent a Java object is determined by the number and the types of its fields. For example, fields of the primitive types, bool, char, byte, short, int, and float typically occupy a single, 32-bit word whereas long and double both require two words of storage. A field which refers to an object or to an interface typically requires only one word.
In addition to the memory required for the fields of an object, there is usually some fixed, constant amount of extra storage set aside in every object. This extra storage carries information used by the Java virtual machine to make sure that object is used correctly and to aid the process of garbage collection.
Every object in a Java program is created explicitly by invoking the new operator. Invoking the new operator causes the Java virtual machine to perform the following steps: