This is an extremely fast and efficient way to allocate storage, second only to registers. The Java compiler must know, while it is creating the program, the exact size and lifetime of all the data that is stored on the stack, because it must generate the code to move the stack pointer up and down. The nice thing about the heap is that, unlike the stack, the compiler doesn't need to know how much storage it needs to allocate from the heap or how long that storage must stay on the heap. Thus, there's a great deal of flexibility in using storage on the heap. Whenever you need to create an object, you simply write the code to create it using new , and the storage is allocated on the heap when that code is executed.
Static storage contains data that is available for the entire time a program is running.
You can use the static keyword to specify that a particular element of an object is static, but Java objects themselves are never placed in static storage. Constant values are often placed directly in the program code, which is safe since they can never change. If data lives completely outside a program it can exist while the program is not running, outside the control of the program. The two primary examples of this are streamed objects , in which objects are turned into streams of bytes, generally to be sent to another machine, and persistent objects , in which the objects are placed on disk so they will hold their state even when the program is terminated. The trick with these types of storage is turning the objects into something that can exist on the other medium, and yet can be resurrected into a regular RAM-based object when necessary.