Skip to content

Commit 02dcf2e

Browse files
bowbahdoeomniprofDainTrain
authored
Bring in some changes (#85)
* Update initialization.md * Add footnote softening the use of "wrong" Co-Authored-By: Ken Fogel <4064849+omniprof@users.noreply.github.com> * Explain backslash and forward slash Co-Authored-By: Dain LaRock <33586731+DainTrain@users.noreply.github.com> * Resolve #54 * Use IO.readln * Add OffsetDateTime chapter * Chapter on Date * Switch and recursion * Loops III * Checkpoint * More reflection * checkpoint * Numerics * IO println * Checkpoint * Update other prints * .. * Remove junk files * Update code runner * Update switch --------- Co-authored-by: Ken Fogel <4064849+omniprof@users.noreply.github.com> Co-authored-by: Dain LaRock <33586731+DainTrain@users.noreply.github.com>
1 parent 492fb9f commit 02dcf2e

File tree

8 files changed

+81
-8
lines changed

8 files changed

+81
-8
lines changed

src/SUMMARY.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,38 @@
1212
- [Tour of Scala](./examples/tour_of_scala.md)
1313
- [tutorialspoint](./examples/tutorialspoint.md)
1414
- [tutorialspoint paid course](./examples/tutorialspoint_paid.md)
15-
- [w3schools](./examples/w3schools.md) -->
15+
- [w3schools](./examples/w3schools.md)
16+
17+
Project ideas:
18+
calorie tracker
19+
tic tac toe
20+
chess
21+
go
22+
CSV
23+
image stuff with the PPM format
24+
25+
swing game - maybe have a simplified game engine
26+
27+
fixed time loop game
28+
29+
opengl/ffm
30+
31+
version control
32+
33+
something with statistics
34+
newton raphston
35+
36+
airplane physics program
37+
ball throw physics program
38+
chemical stuff
39+
40+
(after bytes) Make an audio file. Play hot cross buns.
41+
42+
snake
43+
2048
44+
colors
45+
battleship
46+
-->
1647

1748
# Modern Java
1849

src/collections/factories.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Main {
6262
}
6363
```
6464

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

src/encapsulation/classes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class ArrayList<E> extends AbstractList<E>
5252
}
5353
```
5454

55+
5556
People who write programs that depend on calling `.add` on an `ArrayList` do not need
5657
to understand how or when the internal `elementData` and `size` fields are updated. Those also
5758
need not be the only fields that exist. All that is required is "calling `.add` will add an element to the list."

src/hash_maps/appropriate_keys.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Both objects with reference based and value based definitions of `equals` and `hashCode`
44
are "appropriate" to use as keys in `HashMap`s.
55

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

910
```java

src/hash_maps/value_based_identity.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Value Based Identity
22

3+
34
While reference based identity can be useful, it's often not what you want for keys in a `HashMap`.
45
Ideally if you are looking up `"Tow Mater"` you shouldn't have to be careful to ensure it's the *same*
56
instance of `String`, all you care about is that it contains the right characters.

src/interfaces_ii.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
Interfaces let you describe a common set of methods shared
44
by different implementing classes.
55

6+
67
They can do slightly more than this though and it's helpful
78
to know about.

src/switch/exhaustiveness.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,36 @@ String describe(int number) {
2323
}
2424
```
2525

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

29-
```java,no_run
29+
```java,no_run,does_not_compile
30+
enum Bird {
31+
TURKEY,
32+
EAGLE,
33+
WOODPECKER
34+
}
35+
36+
boolean isScary(Bird bird) {
37+
switch (bird) {
38+
case TURKEY -> {
39+
return true;
40+
}
41+
case EAGLE -> {
42+
return true;
43+
}
44+
case WOODPECKER -> {
45+
return false;
46+
}
47+
}
48+
}
49+
```
50+
51+
This is, unfortunately, not the case for a switch statement.
52+
You either need a `default` case or to have an explicit `case null` to handle the
53+
possibility that the enum value is `null`.[^lies]
54+
55+
```java,no_run,does_not_compile
3056
enum Bird {
3157
TURKEY,
3258
EAGLE,
@@ -44,6 +70,17 @@ boolean isScary(Bird bird) {
4470
case WOODPECKER -> {
4571
return false;
4672
}
73+
// Need to handle the possibility of null
74+
// or give a "default ->"
75+
case null -> {
76+
// You might want to return a value or just crash
77+
return false;
78+
}
4779
}
4880
}
49-
```
81+
```
82+
83+
[^sometimes]: This is sometimes the case! It is really just this specific form of switch that has this restriction.
84+
85+
[^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
86+
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.

theme/book.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ function playground_text(playground, hidden = true) {
115115
let text = playground_text(code_block);
116116

117117
var params = {
118-
release: '22',
118+
release: '25',
119119
runtime: 'latest',
120120
action: 'run',
121-
preview: true,
121+
preview: false,
122122
code: text,
123123
};
124124

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy