Repaso
EspaƱol
Java CoreCoreJV-03

Which statement about int and Integer is correct?

Options

  1. They are the same type, written two different ways
  2. int is a primitive and cannot be null; Integer is an object and can (Correct option)
  3. Integer is always faster than int because it is an object
  4. int can be a generic type argument, as in List<int>

Answer

int is a primitive (cannot be null); Integer is an object wrapper (can be null)

Why

Java has 8 primitive types (int, long, double, boolean, char, byte, short, float). They hold a plain value and can never be null.

Each primitive has a wrapper class (Integer, Long, Double...) that is a real object. It can be null and can be used in collections and generics: List<Integer> works, List<int> does not.

Java converts between them automatically (autoboxing/unboxing). Unboxing a null Integer throws NullPointerException.

Remember

Primitive = raw value. Wrapper = object (can be null).

Key terms

Practice this question in Repaso