I have a question; I don't know if it is dumb or not...but I will ask anyway
We all know that when we say
String name = "someName";
we know that this is a pooled string so it's not going to get on the heap/stack but...
if we say
Integer integer = new Integer(888);
we know this is going to get on the heap...
then
Integer otherInteger = 444;
where is "otherInteger" going to get? what memory location?
Thanks!
String name = "someName"; String is immutable class and String type is reference or non-primitive type, so name reference point to "someName" object, which is placed in "String-constant- pool", in heap.( no stack). Integer is wrapper class( provides the mechanism to convert primitive into object and object into primitive). The code Integer otherInteger = 444; is an example of auto-boxing (https://docs.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html) and compiler automatically converts this line to Integer otherInteger = Integer.valueOf(444); . So, Integer otherInteger= Integer.valueOf(444) return Integer object i.e this placed in heap.