The compiler autoboxes primitive values, this means that
Integer value = 6;
will be compiled as
Integer value = Integer.valueOf(6);
Integer.valueOf will return an Integer instance with the given value. In your case i
will now reference the Integer(6) instead of the Integer(5), the Integer(5) object itself will not change.
To see this you can do following
Integer i = new Integer(5);//assign new integer to i
Integer b = i;//b refences same integer as i
i = 6;//modify i
System.out.println(i +"!="+b);
This will print 6!=5
, if the integer instance had been modified it would print 6!=6
instead.
To clarify this is only meant to show how an assignment to Integer only modifies the reference and does not alter the Integer instance itself. As user @KNU points out it does not prove or show the immutability of Integer, as far as I can tell the immutability is only indirectly given by the lack of modifying methods in its API and the requirement that instances returned by Integer.valueOf have to be cached for a certain range.