What is an integer?

All objects in Java are references and you can use them like pointers ( references )

A reference is an index into a memory management table. Typically the memory management table is protected from direct access. In Java’s case the reference can’t be manipulated manually, as any read of the variable will result in returning the referenced object.

This has a lot of implications, but is necessary for decent automatic garbage collection. Garbage collection sometimes involves moving objects in memory to create larger areas of free space (for needed objects that cannot fit into the current memory holes). If Java exposed a pointer, then after memory compaction, you might have the “old” address of the memory.

By using references, your reference is guaranteed to stay the same, even if the actual location of memory moves around. Internal to the JVM is a reference to pointer table, but you will never get to see it from a running program; because, if you ever touched it, it would mess up the automatic memory management.

A Java both int and Integer are used to store integer type data the major difference between both is type of int is primitive while Integer is of class type. … int helps in storing integer value into memory. Integer helps in converting int into object and to convert an object into int as per requirement

3 Likes