When I started out using Java, it was implied to me that we have two different types:
Objects (strings, from classes, println, etc)
primitive values (int, do
There is an implicit mapping between primitives and objects, so an int
can be used where an Integer
is expected. It is a feature called autoboxing.
For example:
Integer foo = 4; // 4 is really an int
Also, primitives have things in common with objects. They have a Class
, such as int.class
.
It should also be noted that all arrays are objects.
However, the notion of Object vs primitive is one of the worst thing there is in Java. A lot of modern languages simply don't make too much difference between them, or even don't have any primitives. (In java as well, you can do everything without ever using explicitly a primitive).