A new operator creates an object of a class and returns the reference to the memory where the object resides. From a practical standpoint, the variable that holds this reference is treated in the code as if it is the object itself. Such a variable can be a class, an interface, an array, or a null literal that indicates that no memory reference is assigned to the variable. If the type of the reference is an interface, it can be assigned either null or a reference to the object of the class that implements this interface because the interface itself cannot be instantiated.
JVM watches for all the created objects and checks whether there are references to each of them in the currently executed code. If there is an object without any reference to it, JVM removes it from the memory in the process called garbage collection. We will describe this process in Chapter...