GeezerVison is showing robbmalexander.github.io — robbmalexander.github.io
Maps, Primitives, & File I/O
Primitives vs Objects
-
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.
- There are memory access differences between primitives and reference types:
-
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)
- When uninitialized, primitives have default values (like
0 for int) while wrapper objects default to null.
Exceptions
Scanning & Input/Output
-
Java objects called Scanners manage input from outside the program, allowing it to be handled by the program’s logic.
-
Scanners 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.