Skip to content

Latest commit

 

History

History
39 lines (23 loc) · 1.63 KB

401-03.md

File metadata and controls

39 lines (23 loc) · 1.63 KB
layout title permalink
page
401.03 Reading Notes
/401-R03/

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

  • 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.

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.