In Java, Integer is an object type. In this code example, you need a primitive type, which is an int. In Java, any type of object type / reference type or any variable of type Sub of an object type that is not automatically initialized is initialized to zero. Where as a primitive type has a default value.
The reason for this is because Objects provide tools for polymorphism, are passed by reference (or, more precisely, have links passed by value), and are allocated from the heap. Conversely, primitives are immutable types that are passed by value and are often allocated from the stack.
source share