1. 1. Prelude
    ❱
    1. 1.1. Asking for Help
    2. 1.2. Toy Problems
    3. 1.3. Lies
  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. Control Flow I
  12. 10. Branching Paths
    ❱
    1. 10.1. If
    2. 10.2. Nested Ifs
    3. 10.3. Else
    4. 10.4. Else If
    5. 10.5. Relation to Delayed Assignment
    6. 10.6. Scoped Variables
    7. 10.7. Conditional Operator
    8. 10.8. Boolean Expressions
    9. 10.9. Challenges
  13. 11. Loops
    ❱
    1. 11.1. While
    2. 11.2. Endless Loops
    3. 11.3. Break
    4. 11.4. Continue
    5. 11.5. Unreachable Code
    6. 11.6. Do While
    7. 11.7. Nested Loops
    8. 11.8. Labeled Break
    9. 11.9. Labeled Continue
    10. 11.10. Iteration
    11. 11.11. Counting Up
    12. 11.12. Counting Down
    13. 11.13. Iterate over a String
    14. 11.14. Challenges
  14. Data Types II
  15. 12. Arrays
    ❱
    1. 12.1. Array Initializers
    2. 12.2. Length
    3. 12.3. Access Individual Elements
    4. 12.4. Set Individual Elements
    5. 12.5. Aliasing
    6. 12.6. Reassignment
    7. 12.7. Relation to Final Variables
    8. 12.8. Printing the Contents of an Array
    9. 12.9. Empty Array
    10. 12.10. Difference between Initializer and Literal
    11. 12.11. Initialization with new
    12. 12.12. Challenges
  16. Projects
  17. 13. The Boston Molasses Disaster Game
  18. Control Flow II
  19. 14. Loops II
    ❱
    1. 14.1. For
    2. 14.2. For Syntax
    3. 14.3. Counting Up and Down
    4. 14.4. Iterate over a String
    5. 14.5. Iterate over an Array
    6. 14.6. Comparison to while
    7. 14.7. i
    8. 14.8. Break
    9. 14.9. Continue
    10. 14.10. Delayed Assignment
    11. 14.11. Inferred Types
    12. 14.12. Empty Initializers
    13. 14.13. Empty Expressions
    14. 14.14. Empty Statements
    15. 14.15. Final Variables
    16. 14.16. Labeled Break
    17. 14.17. Labeled Continue
    18. 14.18. Drawing Right Triangles
    19. 14.19. Drawing Isosceles Triangles
    20. 14.20. Challenges
  20. Code Structure
  21. 15. Methods
    ❱
    1. 15.1. Declaration
    2. 15.2. Invocation
    3. 15.3. Scope
    4. 15.4. main
    5. 15.5. Challenges
  22. 16. Arguments
    ❱
    1. 16.1. Declaration
    2. 16.2. Invocation with Arguments
    3. 16.3. Reassignment
    4. 16.4. Final Arguments
    5. 16.5. Aliasing
    6. 16.6. Overloading
    7. 16.7. Inferred Types
    8. 16.8. Challenges
  23. 17. Return Values
    ❱
    1. 17.1. Declaration
    2. 17.2. Return Statement
    3. 17.3. Exhaustiveness
    4. 17.4. void
    5. 17.5. Return in void methods
    6. 17.6. Conversion
    7. 17.7. Unreachable Statements
    8. 17.8. Challenges
  24. Projects
  25. 18. Tic-Tac-Toe
  26. Data Types III
  27. 19. null
    ❱
    1. 19.1. Null as Absence
    2. 19.2. Null as Unknown
    3. 19.3. Checking for null
    4. 19.4. NullPointerException
    5. 19.5. Challenges
  28. 20. Boxed Primitives
    ❱
    1. 20.1. Integer
    2. 20.2. Double
    3. 20.3. Character
    4. 20.4. Boolean
    5. 20.5. Unboxing Conversion
    6. 20.6. Boxing Conversion
    7. 20.7. Arrays of Boxed Primitives
    8. 20.8. Challenges
  29. 21. Arrays II
    ❱
    1. 21.1. Initializion with Size
    2. 21.2. Default Values
    3. 21.3. Populate Arrays
    4. 21.4. Challenges
  30. Projects II
  31. 22. Ultimate Tic-Tac-Toe
  32. Code Structure II
  33. 23. Classes
    ❱
    1. 23.1. The meaning of the word Class
    2. 23.2. Class Declaration
    3. 23.3. Naming
    4. 23.4. Instances
    5. 23.5. Fields
    6. 23.6. Field Initialization
    7. 23.7. Field Access
    8. 23.8. Field Default Values
    9. 23.9. Aliasing
    10. 23.10. Return Multiple Values
    11. 23.11. Challenges
  34. 24. Instance Methods
    ❱
    1. 24.1. Invocation
    2. 24.2. Arguments
    3. 24.3. Field Access
    4. 24.4. Field Updates
    5. 24.5. Derived Values
    6. 24.6. Invoke Other Methods
    7. 24.7. this
    8. 24.8. Disambiguation
    9. 24.9. Clarity
    10. 24.10. Challenges
  35. Data Types IV
  36. 25. Enums
    ❱
    1. 25.1. Declaration
    2. 25.2. Variants
    3. 25.3. Naming
    4. 25.4. Usage
    5. 25.5. Equality
    6. 25.6. Comparison to boolean
    7. 25.7. Challenges
  37. 26. Strings II
    ❱
    1. 26.1. lowercase
    2. 26.2. UPPERCASE
    3. 26.3. Equality ignoring case
    4. 26.4. Check if empty
    5. 26.5. Check if blank
    6. 26.6. Strip extra whitespace
    7. 26.7. Challenges
  38. Control Flow III
  39. 27. Exceptions
    ❱
    1. 27.1. throw
    2. 27.2. Messages
    3. 27.3. Stack Traces
    4. 27.4. try/catch
    5. 27.5. Challenges
  40. 28. Switch
    ❱
    1. 28.1. Case and Default
    2. 28.2. Strings
    3. 28.3. ints
    4. 28.4. Enums
    5. 28.5. Omitted Default
    6. 28.6. Exhaustiveness
    7. 28.7. Combining Cases
    8. 28.8. null
    9. 28.9. Challenges
  41. Code Structure III
  42. 29. Constructors
    ❱
    1. 29.1. Declaration
    2. 29.2. The Default Constructor
    3. 29.3. Arguments
    4. 29.4. Final Fields
    5. 29.5. Invariants
    6. 29.6. Overloads
    7. 29.7. Delegation
    8. 29.8. Challenges
  43. 30. Global Fields
    ❱
    1. 30.1. Default Values
    2. 30.2. Final Fields
    3. 30.3. Field Access
    4. 30.4. Inferred Types
    5. 30.5. Challenges
  44. Concepts
  45. 31. Code is Read more than Written
    ❱
    1. 31.1. Meaning
    2. 31.2. Implications
    3. 31.3. Information Density
    4. 31.4. Audience
    5. 31.5. Practice
  46. Interactive Programs
  47. 32. Standard Input
    ❱
    1. 32.1. Prompting
    2. 32.2. Interpreting Input
    3. 32.3. Reprompting
    4. 32.4. Leniency
    5. 32.5. Delayed Assignment
    6. 32.6. Transporting Data
  48. The Computing Environment
  49. 33. Hardware
    ❱
    1. 33.1. CPU
    2. 33.2. RAM
    3. 33.3. Hard Drives
    4. 33.4. Motherboard
  50. 34. Operating Systems
    ❱
    1. 34.1. Personal Computers
    2. 34.2. Servers
    3. 34.3. Mobile Phones
    4. 34.4. Game Consoles
    5. 34.5. Abstractions
    6. 34.6. Defaults
  51. 35. The Terminal
    ❱
    1. 35.1. Bash
    2. 35.2. Windows Subsystem for Linux
    3. 35.3. Chromebooks and School Computers
    4. 35.4. Commands
    5. 35.5. Directories
    6. 35.6. Listing Files
    7. 35.7. Creating Directories
    8. 35.8. Changing Directories
    9. 35.9. Creating Files
    10. 35.10. Run Java Programs
    11. 35.11. Getting Used to it
  52. Control Flow IV
  53. 36. Exceptions II
    ❱
    1. 36.1. Checked Exceptions
    2. 36.2. Unchecked Exceptions
    3. 36.3. throws
    4. 36.4. Propagating Exceptions
    5. 36.5. Rethrowing Exceptions
    6. 36.6. Exception
    7. 36.7. RuntimeException
    8. 36.8. main
  54. 37. Switch II
    ❱
    1. 37.1. Yield
    2. 37.2. Omitted Yield
    3. 37.3. Exhaustiveness
    4. 37.4. Return a Switch
  55. Code Structure IV
  56. 38. Multi-File Programs
    ❱
    1. 38.1. The Sources folder
    2. 38.2. The Main file
    3. 38.3. A Second file
    4. 38.4. File names
    5. 38.5. The Anonymous Main Class
    6. 38.6. Global Fields
  57. 39. Visibility
    ❱
    1. 39.1. Private Methods
    2. 39.2. Private Fields
    3. 39.3. Invariants
    4. 39.4. Accessors
    5. 39.5. Getters and Setters
  58. 40. Static Fields
    ❱
    1. 40.1. Declaration
    2. 40.2. Initialization
    3. 40.3. Usage
    4. 40.4. Constants
    5. 40.5. Controversy
    6. 40.6. Naming
  59. 41. Static Methods
    ❱
    1. 41.1. Declaration
    2. 41.2. Scope
    3. 41.3. Naming
    4. 41.4. Usage
    5. 41.5. Math
    6. 41.6. Factories
  60. Data Structures & Algorithms
  61. 42. Growable Arrays
    ❱
    1. 42.1. Concept
    2. 42.2. Simple Implementation
    3. 42.3. Usage
    4. 42.4. Performance Problems
    5. 42.5. Performance Solutions
    6. 42.6. Optimized Implementation
  62. Interactive Programs II
  63. 43. Command Line Arguments
    ❱
    1. 43.1. Accessing Arguments
    2. 43.2. Conventions
  64. Code Structure V
  65. 44. Inner Classes
    ❱
    1. 44.1. Type
    2. 44.2. Instances
    3. 44.3. New Operator
    4. 44.4. Scope
    5. 44.5. Disambiguation
    6. 44.6. The anonymous main class
    7. 44.7. Static Inner Classes
    8. 44.8. Private Inner Classes
  66. 45. Packages
    ❱
    1. 45.1. Declaration
    2. 45.2. Visibility
    3. 45.3. Public Classes
    4. 45.4. Fully Qualified Class Name
    5. 45.5. Import
    6. 45.6. The Default Package
    7. 45.7. The Anonymous Main Class
    8. 45.8. Public Methods
    9. 45.9. Package-Private Methods
    10. 45.10. Public Fields
    11. 45.11. Package-Private Fields
    12. 45.12. The Default Constructor
    13. 45.13. Public Constructors
    14. 45.14. Package-Private Constructors
    15. 45.15. Subpackages
    16. 45.16. Reverse Domain Name Notation
  67. Data Types IV
  68. 46. Records
    ❱
    1. 46.1. Declaration
    2. 46.2. The Canonical Constructor
    3. 46.3. Component Accessors
    4. 46.4. Component Accessor Visibility
    5. 46.5. Printing a Record
    6. 46.6. Check for Equality
    7. 46.7. Return Multiple Values
    8. 46.8. Shorthand
  69. 47. Integers II
    ❱
    1. 47.1. Integer from a String
    2. 47.2. Integer to a String
    3. 47.3. Base 16 Integer Literals
    4. 47.4. Integer from a Base 16 String
    5. 47.5. Integer to a Base 16 String
    6. 47.6. Underscores in Integer Literals
  70. Interactive Programs III
  71. 48. Files
    ❱
    1. 48.1. Paths
    2. 48.2. IOException
    3. 48.3. UncheckedIOException
    4. 48.4. Write to a File
    5. 48.5. Read from a File
    6. 48.6. Create a Folder
    7. 48.7. Challenges
  72. Code Structure VI
  73. 49. Object
    ❱
    1. 49.1. Subtypes
    2. 49.2. instanceof
    3. 49.3. toString
    4. 49.4. Override toString
    5. 49.5. @Override
    6. 49.6. equals and hashCode
    7. 49.7. Override equals and hashCode
  74. 50. Generics
    ❱
    1. 50.1. Type Variables
    2. 50.2. Naming
    3. 50.3. Instantiation
    4. 50.4. Inference
    5. 50.5. Soundness
    6. 50.6. Raw Types
  75. 51. Interfaces
    ❱
    1. 51.1. Interface Declaration
    2. 51.2. Implementation
    3. 51.3. @Override
    4. 51.4. Naming
    5. 51.5. Subtypes
    6. 51.6. Multiple Implementations
  76. Data Types V
  77. 52. Time
    ❱
    1. 52.1. Instant
    2. 52.2. Duration
    3. 52.3. LocalDate
    4. 52.4. LocalTime
    5. 52.5. LocalDateTime
    6. 52.6. Time Zones
    7. 52.7. ZonedDateTime
    8. 52.8. OffsetDateTime
    9. 52.9. Date
    10. 52.10. Challenges
  78. 53. ArrayList
    ❱
    1. 53.1. Ubiquity
    2. 53.2. Add an item
    3. 53.3. Size
    4. 53.4. Get an item
    5. 53.5. Loop over items
    6. 53.6. Set an item
    7. 53.7. Remove an item
  79. 54. HashMap
    ❱
    1. 54.1. Filing Cabinets
    2. 54.2. Keys and Values
    3. 54.3. Put Items
    4. 54.4. Get Items
    5. 54.5. Hash Functions
    6. 54.6. Hash Collision
    7. 54.7. Hash Distribution
    8. 54.8. Reference Based Identity
    9. 54.9. Value Based Identity
    10. 54.10. Appropriate Keys
  80. Concepts II
  81. 55. Hyrum's Law
    ❱
    1. 55.1. Authority
    2. 55.2. Validity
    3. 55.3. Emergent Properties
    4. 55.4. Importance
  82. Control Flow V
  83. 56. Switch III
    ❱
    1. 56.1. break
    2. 56.2. fallthrough
    3. 56.3. return
    4. 56.4. default
    5. 56.5. yield
  84. 57. Recursion
    ❱
    1. 57.1. Disclaimer
    2. 57.2. Base Case
    3. 57.3. Comparison to Delegation
    4. 57.4. Comparison to Loops
    5. 57.5. Counting Down
    6. 57.6. Accumulators
    7. 57.7. Recurse Over a String
    8. 57.8. Recurse Over an Array
  85. 58. Loops III
    ❱
    1. 58.1. For-each loops
    2. 58.2. Arrays
    3. 58.3. Iterable and Iterator
    4. 58.4. ArrayList
    5. 58.5. String
    6. 58.6. Concurrent Modifications
    7. 58.7. Inferred Types
  86. Concepts II
  87. 59. Encapsulation
    ❱
    1. 59.1. Implementation Details
    2. 59.2. Methods
    3. 59.3. Classes
    4. 59.4. Implicit Interfaces
    5. 59.5. Abstractions
    6. 59.6. Leaky Abstractions
    7. 59.7. Information Hiding
  88. Data Types VI
  89. 60. Collections
    ❱
    1. 60.1. Collection
    2. 60.2. List
    3. 60.3. Map
    4. 60.4. Set
    5. 60.5. Arrays
  90. 61. Multi-Dimensional Arrays
    ❱
    1. 61.1. Declaration
    2. 61.2. Array Initializers
    3. 61.3. Initialization with new
    4. 61.4. Access Individual Elements
    5. 61.5. Set Individual Elements
    6. 61.6. Initialization with Size
    7. 61.7. Default Values
    8. 61.8. Populate Values
    9. 61.9. Ragged Arrays
  91. Metaprogramming
  92. 62. Reflection
    ❱
    1. 62.1. Class Objects
    2. 62.2. Get all Fields
    3. 62.3. Get a Field
    4. 62.4. Read from a Field
    5. 62.5. Write to a Field
    6. 62.6. Get all Methods
    7. 62.7. Get a Method
    8. 62.8. Invoke a Method
    9. 62.9. Get a Constructor
    10. 62.10. Get all Constructors
    11. 62.11. Invoke a Constructor
  93. 63. Annotations
    ❱
    1. 63.1. Declaration
    2. 63.2. Usage
    3. 63.3. Elements
    4. 63.4. Usage with Elements
    5. 63.5. Defaults
    6. 63.6. @Target
    7. 63.7. @Retention
    8. 63.8. Reflective Access
    9. 63.9. @Override
  94. Concepts III
  95. 64. Abbreviations
    ❱
    1. 64.1. Niches
    2. 64.2. Usage Contexts
    3. 64.3. Ambiguity
    4. 64.4. Familiarity
    5. 64.5. Elaboration
  96. Code Structure VII
  97. 65. Interfaces II
    ❱
    1. 65.1. Default Methods
    2. 65.2. Interface Extension
    3. 65.3. Static Methods
    4. 65.4. Private Static Methods
  98. 66. Class Extension
    ❱
    1. 66.1. Extend a Class
    2. 66.2. Protected Fields
    3. 66.3. Protected Methods
    4. 66.4. Relation to Interfaces
    5. 66.5. Relation to Encapsulation
    6. 66.6. Final Classes
  99. 67. Abstract Classes
    ❱
    1. 67.1. Relation to Interfaces
  100. Data Types IV
  101. 68. Niche Numerics
    ❱
    1. 68.1. byte
    2. 68.2. short
    3. 68.3. long
    4. 68.4. Unsigned Operations
    5. 68.5. float
  102. Code Structure VIII
  103. 69. Modules
  104. 70. 🚧 (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;