In Java, the process of converting from a primitive (like int
) to an object with a reference corresponding to that type (like Integer
) is called boxing.
Primitives are stored on the stack and are accessed more quickly. For an int
, 32 bits are required for storage.
Reference objects are stored on the heap and are accessed relatively slowly. For an Integer,
128 bits are required for storage.
These memory differences are further multiplied in the case of arrays (Example chart given in this Baeldung tutorial)
0
for int
) while wrapper objects default to null
.In Java, an exception is an event that does not fit within the defined logical flow of a program.
Exception vocabulary:
A method throws an exception by creating an object defined for that exceptional cirucumstance.
A code block written for such an exception is called the exception handler.
A handler executing code defined for exception is said to be catching the exception.
Java objects called Scanner
s manage input from outside the program, allowing it to be handled by the program’s logic.
Scanner
s break input data into discrete tokens of a defined type (other than char
).
Input from a scan must be terminated with the .close()
method when used.