Skip to content

Bring in some changes #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,38 @@
- [Tour of Scala](./examples/tour_of_scala.md)
- [tutorialspoint](./examples/tutorialspoint.md)
- [tutorialspoint paid course](./examples/tutorialspoint_paid.md)
- [w3schools](./examples/w3schools.md) -->
- [w3schools](./examples/w3schools.md)

Project ideas:
calorie tracker
tic tac toe
chess
go
CSV
image stuff with the PPM format

swing game - maybe have a simplified game engine

fixed time loop game

opengl/ffm

version control

something with statistics
newton raphston

airplane physics program
ball throw physics program
chemical stuff

(after bytes) Make an audio file. Play hot cross buns.

snake
2048
colors
battleship
-->

# Modern Java

Expand Down
1 change: 1 addition & 0 deletions src/collections/factories.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Main {
}
```


If you want the opposite - if you want to make a copy of something like an `ArrayList`
which does not support `.add`, `.remove`, etc. - you can use `copyOf`.

Expand Down
1 change: 1 addition & 0 deletions src/encapsulation/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ArrayList<E> extends AbstractList<E>
}
```


People who write programs that depend on calling `.add` on an `ArrayList` do not need
to understand how or when the internal `elementData` and `size` fields are updated. Those also
need not be the only fields that exist. All that is required is "calling `.add` will add an element to the list."
Expand Down
3 changes: 2 additions & 1 deletion src/hash_maps/appropriate_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Both objects with reference based and value based definitions of `equals` and `hashCode`
are "appropriate" to use as keys in `HashMap`s.

The most important thing to be careful of is using objects where`equals` and `hashCode`

The most important thing to be careful of is using objects where `equals` and `hashCode`
are value based, but the object itself is mutable.

```java
Expand Down
1 change: 1 addition & 0 deletions src/hash_maps/value_based_identity.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Value Based Identity


While reference based identity can be useful, it's often not what you want for keys in a `HashMap`.
Ideally if you are looking up `"Tow Mater"` you shouldn't have to be careful to ensure it's the *same*
instance of `String`, all you care about is that it contains the right characters.
Expand Down
1 change: 1 addition & 0 deletions src/interfaces_ii.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
Interfaces let you describe a common set of methods shared
by different implementing classes.


They can do slightly more than this though and it's helpful
to know about.
45 changes: 41 additions & 4 deletions src/switch/exhaustiveness.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,36 @@ String describe(int number) {
}
```

When you have something like an enum you don't need a `default` case
because you can handle every variant explicitly.
When you have something like an enum you might think you don't need a `default` case
because you can handle every variant explicitly.[^sometimes]

```java,no_run
```java,no_run,does_not_compile
enum Bird {
TURKEY,
EAGLE,
WOODPECKER
}

boolean isScary(Bird bird) {
switch (bird) {
case TURKEY -> {
return true;
}
case EAGLE -> {
return true;
}
case WOODPECKER -> {
return false;
}
}
}
```

This is, unfortunately, not the case for a switch statement.
You either need a `default` case or to have an explicit `case null` to handle the
possibility that the enum value is `null`.[^lies]

```java,no_run,does_not_compile
enum Bird {
TURKEY,
EAGLE,
Expand All @@ -44,6 +70,17 @@ boolean isScary(Bird bird) {
case WOODPECKER -> {
return false;
}
// Need to handle the possibility of null
// or give a "default ->"
case null -> {
// You might want to return a value or just crash
return false;
}
}
}
```
```

[^sometimes]: This is sometimes the case! It is really just this specific form of switch that has this restriction.

[^lies]: Remember at the very start when I said I was going to lie to you? This is one of those lies. The real reason for this restriction has to do with how Java compiles switch statements and a concept called "separate compilation." Basically
even though we know you covered all the enum variants, Java still makes you account for if a new enum variant was added later on. It doesn't do this for all forms of `switch` though.
4 changes: 2 additions & 2 deletions theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ function playground_text(playground, hidden = true) {
let text = playground_text(code_block);

var params = {
release: '22',
release: '25',
runtime: 'latest',
action: 'run',
preview: true,
preview: false,
code: text,
};

Expand Down