☕ Java Beginner

What is the difference between int and Integer in Java?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Java topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

int is a primitive data type that stores a 32-bit signed integer value directly. It cannot be null, cannot be used as a generic type parameter, and is more memory-efficient. Integer is the wrapper class for int — an object that wraps the primitive value. It can be null, can be used in collections (like List<Integer>), and provides utility methods like Integer.parseInt(), Integer.MAX_VALUE. Java automatically converts between them via autoboxing (int → Integer) and unboxing (Integer → int).

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.