Objects created with the new keyword are stored on the heap.
Variables (references to these objects) and primitive types such as int are stored in the program stack.
Integer not a special class in Java. You can use arithmetic operators with it, they are immutable, and you can even use == to test equality (in the range of -128 to 127, since these values are already cached).
Is there any concept like Integer-Pool, how do we have String-Pool for String?
Open the java.lang.Integer code and look at the valueOf method. Obviously, they really use the Integer pool.
public static Integer valueOf(int i) { assert IntegerCache.high >= 127; if (i >= IntegerCache.low && i <= IntegerCache.high) return IntegerCache.cache[i + (-IntegerCache.low)]; return new Integer(i); }
In addition, I think this image will be useful to you:

source share