1. 1. Prelude
    1. 1.1. Asking for Help
    2. 1.2. Toy Problems
    3. 1.3. Lies
    4. 1.4. AI
    5. 1.5. Java
  2. 2. Getting Started
  3. 3. First Steps
    1. 3.1. Comments
    2. 3.2. Semicolons
    3. 3.3. Formatting
    4. 3.4. Challenges
  4. 4. Local Variables
    1. 4.1. Naming
    2. 4.2. Reassignment
    3. 4.3. Delayed Assignment
    4. 4.4. Types
    5. 4.5. Final Variables
    6. 4.6. Inferred Types
    7. 4.7. Challenges
  5. Data Types I
  6. 5. Booleans
    1. 5.1. Not
    2. 5.2. And
    3. 5.3. Or
    4. 5.4. Operator Precedence
    5. 5.5. Challenges
  7. 6. Integers
    1. 6.1. Integer Literals
    2. 6.2. Addition
    3. 6.3. Subtraction
    4. 6.4. Multiplication
    5. 6.5. Division
    6. 6.6. Remainder
    7. 6.7. Equality
    8. 6.8. Comparison
    9. 6.9. Chained Comparisons
    10. 6.10. Operator Precedence
    11. 6.11. Reassignment
    12. 6.12. Shorthands for Reassignment
    13. 6.13. Limits
    14. 6.14. Challenges
  8. 7. Floating Point Numbers
    1. 7.1. Floating Point Literals
    2. 7.2. Accuracy
    3. 7.3. Addition
    4. 7.4. Subtraction
    5. 7.5. Multiplication
    6. 7.6. Division
    7. 7.7. Equality
    8. 7.8. Comparison
    9. 7.9. Shorthands for Reassignment
    10. 7.10. NaN
    11. 7.11. Positive and Negative Infinity
    12. 7.12. Square Root
    13. 7.13. Conversion to Integers
    14. 7.14. Conversion from Integers
    15. 7.15. Challenges
  9. 8. Characters
    1. 8.1. Character Literals
    2. 8.2. Common Escape Sequences
    3. 8.3. Conversion to Integers
    4. 8.4. Conversion from Integers
    5. 8.5. Unicode
    6. 8.6. Challenges
  10. 9. Strings
    1. 9.1. String Literals
    2. 9.2. Common Escape Sequences
    3. 9.3. The Empty String
    4. 9.4. Multiline String Literals
    5. 9.5. Concatenation
    6. 9.6. Equality
    7. 9.7. Length
    8. 9.8. Access Individual Characters
    9. 9.9. Challenges
  11. Interactive Programs
  12. 10. Standard Input
    1. 10.1. Prompting
    2. 10.2. Interpreting Input
    3. 10.3. Integers
    4. 10.4. Floating Point Numbers
    5. 10.5. Other Types
    6. 10.6. Challenges
  13. Control Flow I
  14. 11. Branching Paths
    1. 11.1. If
    2. 11.2. Nested Ifs
    3. 11.3. Else
    4. 11.4. Else If
    5. 11.5. Relation to Delayed Assignment
    6. 11.6. Scoped Variables
    7. 11.7. Conditional Operator
    8. 11.8. Boolean Expressions
    9. 11.9. Challenges
  15. 12. Loops
    1. 12.1. While
    2. 12.2. Endless Loops
    3. 12.3. Break
    4. 12.4. Continue
    5. 12.5. Unreachable Code
    6. 12.6. Do While
    7. 12.7. Nested Loops
    8. 12.8. Labeled Break
    9. 12.9. Labeled Continue
    10. 12.10. Iteration
    11. 12.11. Counting Up
    12. 12.12. Counting Down
    13. 12.13. Iterate over a String
    14. 12.14. Challenges
  16. Projects
  17. 13. Prelude
  18. 14. Calorie Tracker
  19. Data Types II
  20. 15. Arrays
    1. 15.1. Array Initializers
    2. 15.2. Length
    3. 15.3. Access Individual Elements
    4. 15.4. Set Individual Elements
    5. 15.5. Aliasing
    6. 15.6. Reassignment
    7. 15.7. Relation to Final Variables
    8. 15.8. Printing the Contents of an Array
    9. 15.9. Empty Array
    10. 15.10. Difference between Initializer and Literal
    11. 15.11. Initialization with new
    12. 15.12. Challenges
  21. Control Flow II
  22. 16. Loops II
    1. 16.1. For
    2. 16.2. For Syntax
    3. 16.3. Counting Up and Down
    4. 16.4. Iterate over a String
    5. 16.5. Iterate over an Array
    6. 16.6. Comparison to while
    7. 16.7. i
    8. 16.8. Break
    9. 16.9. Continue
    10. 16.10. Delayed Assignment
    11. 16.11. Inferred Types
    12. 16.12. Empty Initializers
    13. 16.13. Empty Expressions
    14. 16.14. Empty Statements
    15. 16.15. Final Variables
    16. 16.16. Labeled Break
    17. 16.17. Labeled Continue
    18. 16.18. Drawing Right Triangles
    19. 16.19. Drawing Isosceles Triangles
    20. 16.20. Challenges
  23. Code Structure
  24. 17. Methods
    1. 17.1. Declaration
    2. 17.2. Invocation
    3. 17.3. Scope
    4. 17.4. main
    5. 17.5. Challenges
  25. 18. Arguments
    1. 18.1. Declaration
    2. 18.2. Invocation with Arguments
    3. 18.3. Reassignment
    4. 18.4. Final Arguments
    5. 18.5. Aliasing
    6. 18.6. Overloading
    7. 18.7. Inferred Types
    8. 18.8. Challenges
  26. 19. Return Values
    1. 19.1. Declaration
    2. 19.2. Return Statement
    3. 19.3. Exhaustiveness
    4. 19.4. void
    5. 19.5. Return in void methods
    6. 19.6. Conversion
    7. 19.7. Unreachable Statements
    8. 19.8. Challenges
  27. Data Types III
  28. 20. Multi-Dimensional Arrays
    1. 20.1. Declaration
    2. 20.2. Array Initializers
    3. 20.3. Initialization with new
    4. 20.4. Access Individual Elements
    5. 20.5. Set Individual Elements
    6. 20.6. Initialization with Size
    7. 20.7. Default Values
    8. 20.8. Populate Values
    9. 20.9. Ragged Arrays
    10. 20.10. Challenges
  29. Projects
  30. 21. ASCII Art Generator
  31. Data Types IV
  32. 22. null
    1. 22.1. Null as Absence
    2. 22.2. Null as Unknown
    3. 22.3. Checking for null
    4. 22.4. NullPointerException
    5. 22.5. Challenges
  33. 23. Boxed Primitives
    1. 23.1. Integer
    2. 23.2. Double
    3. 23.3. Character
    4. 23.4. Boolean
    5. 23.5. Unboxing Conversion
    6. 23.6. Boxing Conversion
    7. 23.7. Arrays of Boxed Primitives
    8. 23.8. Challenges
  34. 24. Arrays II
    1. 24.1. Initializion with Size
    2. 24.2. Default Values
    3. 24.3. Populate Arrays
    4. 24.4. Challenges
  35. Code Structure II
  36. 25. Classes
    1. 25.1. The meaning of the word Class
    2. 25.2. Class Declaration
    3. 25.3. Naming
    4. 25.4. Instances
    5. 25.5. Fields
    6. 25.6. Field Initialization
    7. 25.7. Field Access
    8. 25.8. Field Default Values
    9. 25.9. Aliasing
    10. 25.10. Return Multiple Values
    11. 25.11. Challenges
  37. 26. Instance Methods
    1. 26.1. Invocation
    2. 26.2. Arguments
    3. 26.3. Field Access
    4. 26.4. Field Updates
    5. 26.5. Derived Values
    6. 26.6. Invoke Other Methods
    7. 26.7. this
    8. 26.8. Disambiguation
    9. 26.9. Clarity
    10. 26.10. Challenges
  38. Projects
  39. 27. Point of Sale System
  40. Data Types V
  41. 28. Enums
    1. 28.1. Declaration
    2. 28.2. Variants
    3. 28.3. Naming
    4. 28.4. Usage
    5. 28.5. Equality
    6. 28.6. Comparison to boolean
    7. 28.7. Challenges
  42. 29. Strings II
    1. 29.1. lowercase
    2. 29.2. UPPERCASE
    3. 29.3. Equality ignoring case
    4. 29.4. Check if empty
    5. 29.5. Check if blank
    6. 29.6. Strip extra whitespace
    7. 29.7. Challenges
  43. Control Flow III
  44. 30. Exceptions
    1. 30.1. throw
    2. 30.2. Messages
    3. 30.3. Stack Traces
    4. 30.4. try/catch
    5. 30.5. Challenges
  45. 31. Switch
    1. 31.1. Case and Default
    2. 31.2. Strings
    3. 31.3. ints
    4. 31.4. Enums
    5. 31.5. Omitted Default
    6. 31.6. Combining Cases
    7. 31.7. null
    8. 31.8. Exhaustiveness
    9. 31.9. Challenges
  46. Interactive Programs II
  47. 32. Standard Input II
    1. 32.1. Reprompting
    2. 32.2. Enums
    3. 32.3. Delayed Assignment
    4. 32.4. Leniency
    5. 32.5. Aggregating Data
    6. 32.6. Challenges
  48. Code Structure III
  49. 33. Constructors
    1. 33.1. Declaration
    2. 33.2. The Default Constructor
    3. 33.3. Arguments
    4. 33.4. Final Fields
    5. 33.5. Invariants
    6. 33.6. Overloads
    7. 33.7. Delegation
    8. 33.8. Challenges
  50. 34. Global Fields
    1. 34.1. Default Values
    2. 34.2. Final Fields
    3. 34.3. Field Access
    4. 34.4. Inferred Types
    5. 34.5. Challenges
  51. Projects
  52. 35. Tic-Tac-Toe
  53. Concepts
  54. 36. Code is Read more than Written
    1. 36.1. Meaning
    2. 36.2. Implications
    3. 36.3. Information Density
    4. 36.4. Audience
    5. 36.5. Practice
  55. The Computing Environment
  56. 37. Hardware
    1. 37.1. CPU
    2. 37.2. RAM
    3. 37.3. Hard Drives
    4. 37.4. Motherboard
  57. 38. Operating Systems
    1. 38.1. Personal Computers
    2. 38.2. Servers
    3. 38.3. Mobile Phones
    4. 38.4. Game Consoles
    5. 38.5. Abstractions
    6. 38.6. Defaults
  58. 39. The Terminal
    1. 39.1. Bash
    2. 39.2. Windows Subsystem for Linux
    3. 39.3. Chromebooks and School Computers
    4. 39.4. Commands
    5. 39.5. Directories
    6. 39.6. Listing Files
    7. 39.7. Creating Directories
    8. 39.8. Changing Directories
    9. 39.9. Creating Files
    10. 39.10. Run Java Programs
    11. 39.11. Getting Used to it
  59. Control Flow IV
  60. 40. Exceptions II
    1. 40.1. Checked Exceptions
    2. 40.2. Unchecked Exceptions
    3. 40.3. throws
    4. 40.4. Propagating Exceptions
    5. 40.5. Exception
    6. 40.6. RuntimeException
    7. 40.7. Rethrowing Exceptions
    8. 40.8. main
    9. 40.9. Challenges
  61. 41. Switch II
    1. 41.1. Yield
    2. 41.2. Omitted Yield
    3. 41.3. Exhaustiveness
    4. 41.4. Return a Switch
    5. 41.5. Challenges
  62. Code Structure IV
  63. 42. Multi-File Programs
    1. 42.1. The Sources folder
    2. 42.2. The Main file
    3. 42.3. A Second file
    4. 42.4. File names
    5. 42.5. The Anonymous Main Class
    6. 42.6. Global Fields
    7. 42.7. Challenges
  64. 43. Visibility
    1. 43.1. Private Methods
    2. 43.2. Private Fields
    3. 43.3. Invariants
    4. 43.4. Accessors
    5. 43.5. Getters and Setters
    6. 43.6. Challenges
  65. 44. Static Fields
    1. 44.1. Declaration
    2. 44.2. Initialization
    3. 44.3. Usage
    4. 44.4. Constants
    5. 44.5. Controversy
    6. 44.6. Naming
    7. 44.7. Challenges
  66. 45. Static Methods
    1. 45.1. Declaration
    2. 45.2. Scope
    3. 45.3. Naming
    4. 45.4. Usage
    5. 45.5. Math
    6. 45.6. Factories
    7. 45.7. Challenges
  67. Data Structures & Algorithms
  68. 46. Growable Arrays
    1. 46.1. Concept
    2. 46.2. Simple Implementation
    3. 46.3. Usage
    4. 46.4. Performance Problems
    5. 46.5. Performance Solutions
    6. 46.6. Optimized Implementation
    7. 46.7. Challenges
  69. Interactive Programs III
  70. 47. Command Line Arguments
    1. 47.1. Accessing Arguments
    2. 47.2. Conventions
    3. 47.3. Challenges
  71. Code Structure V
  72. 48. Inner Classes
    1. 48.1. Type
    2. 48.2. Instances
    3. 48.3. New Operator
    4. 48.4. Scope
    5. 48.5. Disambiguation
    6. 48.6. The anonymous main class
    7. 48.7. Static Inner Classes
    8. 48.8. Private Inner Classes
    9. 48.9. Challenges
  73. 49. Packages
    1. 49.1. Declaration
    2. 49.2. Visibility
    3. 49.3. Public Classes
    4. 49.4. Fully Qualified Class Name
    5. 49.5. Import
    6. 49.6. Package Imports
    7. 49.7. The Default Package
    8. 49.8. The Anonymous Main Class
    9. 49.9. Public Methods
    10. 49.10. Package-Private Methods
    11. 49.11. Public Fields
    12. 49.12. Package-Private Fields
    13. 49.13. The Default Constructor
    14. 49.14. Public Constructors
    15. 49.15. Package-Private Constructors
    16. 49.16. Subpackages
    17. 49.17. Reverse Domain Name Notation
    18. 49.18. Challenges
  74. Data Types VI
  75. 50. Records
    1. 50.1. Declaration
    2. 50.2. The Canonical Constructor
    3. 50.3. Component Accessors
    4. 50.4. Component Accessor Visibility
    5. 50.5. Printing a Record
    6. 50.6. Check for Equality
    7. 50.7. Return Multiple Values
    8. 50.8. Shorthand
    9. 50.9. Challenges
  76. 51. Integers II
    1. 51.1. Integer from a String
    2. 51.2. Integer to a String
    3. 51.3. Base 16 Integer Literals
    4. 51.4. Integer from a Base 16 String
    5. 51.5. Integer to a Base 16 String
    6. 51.6. Underscores in Integer Literals
    7. 51.7. Challenges
  77. Interactive Programs IV
  78. 52. Files
    1. 52.1. Paths
    2. 52.2. IOException
    3. 52.3. UncheckedIOException
    4. 52.4. Write to a File
    5. 52.5. Read from a File
    6. 52.6. Create a Folder
    7. 52.7. Challenges
  79. Projects
  80. 53. Data Visualization
  81. Code Structure VI
  82. 54. Object
    1. 54.1. Subtypes
    2. 54.2. instanceof
    3. 54.3. toString
    4. 54.4. Override toString
    5. 54.5. @Override
    6. 54.6. equals and hashCode
    7. 54.7. Override equals and hashCode
    8. 54.8. Challenges
  83. 55. Generics
    1. 55.1. Type Variables
    2. 55.2. Naming
    3. 55.3. Instantiation
    4. 55.4. Inference
    5. 55.5. Soundness
    6. 55.6. Raw Types
    7. 55.7. Challenges
  84. 56. Interfaces
    1. 56.1. Interface Declaration
    2. 56.2. Implementation
    3. 56.3. @Override
    4. 56.4. Naming
    5. 56.5. Subtypes
    6. 56.6. Multiple Implementations
    7. 56.7. Challenges
  85. Data Types VII
  86. 57. Time
    1. 57.1. Instant
    2. 57.2. Duration
    3. 57.3. LocalDate
    4. 57.4. LocalTime
    5. 57.5. LocalDateTime
    6. 57.6. Time Zones
    7. 57.7. ZonedDateTime
    8. 57.8. OffsetDateTime
    9. 57.9. Date
    10. 57.10. Challenges
  87. 58. ArrayList
    1. 58.1. Ubiquity
    2. 58.2. Add an item
    3. 58.3. Size
    4. 58.4. Get an item
    5. 58.5. Loop over items
    6. 58.6. Set an item
    7. 58.7. Remove an item
    8. 58.8. Challenges
  88. 59. HashMap
    1. 59.1. Filing Cabinets
    2. 59.2. Keys and Values
    3. 59.3. Put Items
    4. 59.4. Get Items
    5. 59.5. Hash Functions
    6. 59.6. Hash Collision
    7. 59.7. Hash Distribution
    8. 59.8. Reference Based Identity
    9. 59.9. Value Based Identity
    10. 59.10. Appropriate Keys
    11. 59.11. Ubiquity
    12. 59.12. Challenges
  89. Concepts II
  90. 60. Hyrum's Law
    1. 60.1. Authority
    2. 60.2. Validity
    3. 60.3. Emergent Properties
    4. 60.4. Importance
  91. Control Flow V
  92. 61. Switch III
    1. 61.1. break
    2. 61.2. fallthrough
    3. 61.3. return
    4. 61.4. default
    5. 61.5. yield
    6. 61.6. Challenges
  93. 62. Recursion
    1. 62.1. Disclaimer
    2. 62.2. Base Case
    3. 62.3. Comparison to Delegation
    4. 62.4. Comparison to Loops
    5. 62.5. Counting Down
    6. 62.6. Accumulators
    7. 62.7. Recurse Over a String
    8. 62.8. Recurse Over an Array
    9. 62.9. Challenges
  94. 63. Loops III
    1. 63.1. For-each loops
    2. 63.2. Arrays
    3. 63.3. Iterable and Iterator
    4. 63.4. ArrayList
    5. 63.5. String
    6. 63.6. Concurrent Modifications
    7. 63.7. Inferred Types
    8. 63.8. Challenges
  95. Concepts III
  96. 64. Encapsulation
    1. 64.1. Implementation Details
    2. 64.2. Implicit Interfaces
    3. 64.3. Methods
    4. 64.4. Classes
    5. 64.5. Abstraction
    6. 64.6. Coupling
    7. 64.7. Leaky Abstractions
    8. 64.8. Information Hiding
  97. Data Types VIII
  98. 65. Collections
    1. 65.1. List
    2. 65.2. Map
    3. 65.3. Set
    4. 65.4. Arrays
    5. 65.5. UnsupportedOperationException
    6. 65.6. Factories
    7. 65.7. Specificity
    8. 65.8. Challenges
  99. Metaprogramming
  100. 66. Reflection
    1. 66.1. Class Objects
    2. 66.2. Get all Fields
    3. 66.3. Get a Field
    4. 66.4. Read from a Field
    5. 66.5. Write to a Field
    6. 66.6. Get all Methods
    7. 66.7. Get a Method
    8. 66.8. Invoke a Method
    9. 66.9. Get a Constructor
    10. 66.10. Get all Constructors
    11. 66.11. Invoke a Constructor
    12. 66.12. Challenges
  101. 67. Annotations
    1. 67.1. Declaration
    2. 67.2. Usage
    3. 67.3. Elements
    4. 67.4. Usage with Elements
    5. 67.5. Defaults
    6. 67.6. @Target
    7. 67.7. @Retention
    8. 67.8. Reflective Access
    9. 67.9. @Override
    10. 67.10. Challenges
  102. Code Structure VII
  103. 68. Interfaces II
    1. 68.1. Default Methods
    2. 68.2. Interface Extension
    3. 68.3. Static Methods
    4. 68.4. Static Fields
    5. 68.5. Challenges
  104. 69. Class Extension
    1. 69.1. Extend a Class
    2. 69.2. Inheritance
    3. 69.3. Override
    4. 69.4. Protected
    5. 69.5. Abstract Classes
    6. 69.6. Abstract Methods
    7. 69.7. Relation to Interfaces
    8. 69.8. Relation to Encapsulation
    9. 69.9. Final Classes
    10. 69.10. Challenges
  105. Data Types IX
  106. 70. Niche Numerics
    1. 70.1. byte
    2. 70.2. short
    3. 70.3. long
    4. 70.4. Unsigned Operations
    5. 70.5. float
    6. 70.6. Challenges
  107. Projects
  108. 71. Music Maker
  109. Code Structure VIII
  110. 72. Modules
    1. 72.1. Declaration
    2. 72.2. Restrictions
    3. 72.3. Exports
    4. 72.4. Requires
    5. 72.5. Module Imports
    6. 72.6. java.base
    7. 72.7. The Unnamed Module
    8. 72.8. Multi-Module Directory Layout
    9. 72.9. Purpose
    10. 72.10. Challenges
  111. 73. Lambdas
    1. 73.1. Functional Interfaces
    2. 73.2. @FunctionalInterface
    3. 73.3. Lambda Expressions
    4. 73.4. Arguments
    5. 73.5. Return
    6. 73.6. Method References
    7. 73.7. Inference
    8. 73.8. Built-In Functional Interfaces
    9. 73.9. Checked Exceptions
    10. 73.10. Challenges
  112. Sharing Code
  113. 74. Compilation
    1. 74.1. javac
    2. 74.2. Class Files
    3. 74.3. Modules
    4. 74.4. Compile Multiple Files
    5. 74.5. Clean
    6. 74.6. -g
    7. 74.7. Running Compiled Code
    8. 74.8. Challenges
  114. 75. Packaging
    1. 75.1. jar
    2. 75.2. Jar Files
    3. 75.3. --module-path
    4. 75.4. --main-class
    5. 75.5. Libraries
    6. 75.6. Challenges
  115. Tools
  116. 76. just
    1. 76.1. Installation
    2. 76.2. Justfile
    3. 76.3. Recipes
    4. 76.4. Dependencies
    5. 76.5. Documentation Comments
    6. 76.6. Further Reading
    7. 76.7. Challenges
  117. Sharing Code II
  118. 77. Documentation
    1. 77.1. Documentation Comments
    2. 77.2. Format
    3. 77.3. javadoc
    4. 77.4. Challenges
  119. Data Types X
  120. 78. Streams
    1. 78.1. stream
    2. 78.2. map
    3. 78.3. filter
    4. 78.4. Terminal Operations
    5. 78.5. Collectors
    6. 78.6. Purpose
    7. 78.7. Challenges
  121. Conclusion
  122. 79. What Now?
  123. 80. 🚧 (More Chapters Planned) 🚧

Modern Java

Integers

An integer is any number in the set { ..., -2, -1, 0, 1, 2, ... }.

int x = 1;
int y = 8;
int z = -4;