layout | title | permalink |
---|---|---|
page |
401.03 Reading Notes |
/401-R03/ |
-
In Java, the process of converting from a primitive (like
int
) to an object with a reference corresponding to that type (likeInteger
) 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
forint
) while wrapper objects default tonull
.
-
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 thanchar
). -
Input from a scan must be terminated with the
.close()
method when used.