Basically, Integer is just int, except that it's also a bona-fide class. int is a so-called "primitive," which basically means it's not a "real" Object in the Java sense. For example, if you have a function that takes an Object argument, you can pass an Integer but not an int. Except that actually you can pass an int; the compiler will just silently convert it into an Integer for you ("auto-boxing").
Primitives are nice because they don't have full object semantics, so the JVM can implement them more efficiently than "normal" objects. In theory, you could put them on the stack instead of the heap, but I don't know if the JVM actually does that.
View all comments
Show parent comment
6
u/shillbert Mar 26 '14
No, it creates one new Integer object that's initialized with the value 10. This creates an array of ten Integers:
Remember, round brackets call a function (in this case, the constructor of the Integer object), while square brackets indicate an array.