Skip to content
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
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ Gui stuff
- [Field Initialization](./classes/field_initialization.md)
- [Field Access](./classes/field_access.md)
- [Field Default Values](./classes/field_default_values.md)
- [Multiple Instances](./classes/multiple_instances.md)
- [Aliasing](./classes/aliasing.md)
- [Return Multiple Values](./classes/return_multiple_values.md)
- [Challenges](./classes/challenges.md)
Expand Down
2 changes: 1 addition & 1 deletion src/arrays/set_individual_elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ IO.println(
+ response[4]
);

response[2] = "is";
response[index] = "is";
IO.println(
response[0]
+ " "
Expand Down
26 changes: 26 additions & 0 deletions src/classes/multiple_instances.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Multiple Instances

If you make multiple instances of a class with `new`
those classes will each have their own values for
fields.

```java
class Muppet {
String name;
}

void main() {
Muppet kermit = new Muppet();
kermit.name = "Kermit The Frog";

Muppet animal = new Muppet();
animal.name = "animal";

// kermit and animal are distinct muppets
// and thus each have their own name.
IO.println(kermit.name);
IO.println(animal.name);
}
```

Each instance has what we would call its own "identity."
4 changes: 2 additions & 2 deletions src/conclusion/what_now.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ to in order to render websites.
There are a lot of tools for this in Java. A lot a lot. I would recommend
starting with the one that comes built-in: the `jdk.httpserver` module.

[Docs for `jdk.httpserver` here](https://docs.oracle.com/en/java/javase/25/docs/api/jdk.httpserver/module-summary.html)
[Docs for `jdk.httpserver` here](https://javadoc.mccue.dev/api/jdk.httpserver/module-summary.html)

Then you will need to learn about SQL databases and how to query from/insert into them from Java.

Expand Down Expand Up @@ -147,7 +147,7 @@ two paths.
Path #1 is to learn Java Swing. This is an old crusty GUI framework that is kinda difficult to use
but has the pro of coming with Java and being able to run on every potato in existence.

[Docs for `java.desktop` (Swing) here](https://docs.oracle.com/en/java/javase/25/docs/api/java.desktop/module-summary.html)
[Docs for `java.desktop` (Swing) here](https://javadoc.mccue.dev/api/java.desktop/module-summary.html)

Path #2 is the learn JavaFX. By all accounts JavaFX is better software than Swing, but it was cursed
by coming out at a point in history where desktop apps were no longer big business to develop. It
Expand Down
2 changes: 1 addition & 1 deletion src/documentation/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Fix these by documenting that code enough that `javadoc` no longer gives you war

## Challenge 3.

Read the [documentation for java.util.StringJoiner](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/StringJoiner.html).
Read the [documentation for java.util.StringJoiner](https://javadoc.mccue.dev/api/java.base/java/util/StringJoiner.html).

If you can, alter one of your projects to use it.
2 changes: 1 addition & 1 deletion src/documentation/javadoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ javadoc \
This will produce a directory full of HTML files that contain all
the documentation from the specified modules.

This is what is used to make [the official Java documenation](https://docs.oracle.com/en/java/javase/25/docs/api/index.html) as well as at least part of the documentation for most Java libraries.
This is what is used to make [the official Java documenation](https://javadoc.mccue.dev/api/index.html) as well as at least part of the documentation for most Java libraries.

[^theme]: As is a theme with command-line tools
3 changes: 3 additions & 0 deletions src/first_steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ You should get in the habit of, whenever you see some bit of code, trying to phy
tweak it, and play with it.

So try playing around with this program. If you actively engage then you will retain information better.

A lot of the code samples in the book are runnable in your browser. Hover
your mouse on the one above. You should see a run button in the top right.
2 changes: 1 addition & 1 deletion src/hash_maps/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Main {
```

If you feel like this is hard to do with just `.put` and `.get`, you can
check for [other methods on HashMap that can help you](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/HashMap.html).
check for [other methods on HashMap that can help you](https://javadoc.mccue.dev/api/java.base/java/util/HashMap.html).

## Challenge 3.

Expand Down
Binary file added src/interfaces/cat_dog.mp4
Binary file not shown.
5 changes: 5 additions & 0 deletions src/interfaces/multiple_implementations.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ void main() {
barkAndFetch(new Cat());
}
```

<details>
<summary>Think a cat won't behave like a dog?</summary>
<video style="height: 600px" autoplay muted controls src="/interfaces/cat_dog.mp4"></video>
</details>
7 changes: 6 additions & 1 deletion src/lambdas/method_references.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ interface Drummer {
void drum();
}

interface Musician {
void play();
}

class Main {
void doDrum() {
IO.println("ratatatatat");
Expand All @@ -46,7 +50,8 @@ class Main {
Drummer drummer = this::doDrum;
drummer.drum();

Runnable run = drummer::drum;
Musician musician = drummer::drum;
musician.play();
}
}
```
Expand Down
4 changes: 4 additions & 0 deletions src/loops/continue.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ int x = 5;
while (x > 0) {
if (x == 4) {
x--; // Make sure the loop continues to 3
// When this line is reached it will skip
// all the lines after this in the function
// and immediately go back to the top of the
// loop
continue;
}
IO.println(x + " is a good number");
Expand Down
4 changes: 3 additions & 1 deletion src/loops/endless_loops.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Endless Loops

If a while loop will never end, we call that an endless loop.
If a while loop will never end, we call that an endless loop[^hot].

This can happen if the condition is a constant like `while (true)`

Expand All @@ -26,3 +26,5 @@ while (x != 1) {

Many games should never really "finish" so at the very start of that sort of program it is not uncommon
to see a `while (true)`.

[^hot]: If you run an endless loop that does nothing but loop your computer might start overheating. This is a natural part of the process and ultimately healthy for your CPU fans.
2 changes: 1 addition & 1 deletion src/loops_ii/drawing_right_triangles.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Drawing Right Triangles

One of the more fun things to do with `for` loops[^quiz] is to use them to print out shapes.
One of the more fun things to do with `for` loops is to use them to print out shapes.

Say you wanted to draw this right triangle.

Expand Down
4 changes: 2 additions & 2 deletions src/loops_iii/iterable_and_iterator.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
For things that are not arrays, a for-each loops
are built on top of two interfaces: `java.lang.Iterable` and `java.lang.Iterator`.

The [`Iterator`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/Iterator.html) interface defines two methods: `hasNext` and `next`[^remove]. Iterators let you box up the logic of
The [`Iterator`](https://javadoc.mccue.dev/api/java.base/java/util/Iterator.html) interface defines two methods: `hasNext` and `next`[^remove]. Iterators let you box up the logic of
how to loop over something.

```java,no_run
Expand All @@ -17,7 +17,7 @@ public interface Iterator<T> {
}
```

[`Iterable`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/Iterable.html) then
[`Iterable`](https://javadoc.mccue.dev/api/java.base/java/util/Iterable.html) then
just has one method which gives you an `Iterator`.

```java,no_run
Expand Down
2 changes: 2 additions & 0 deletions src/methods/void.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ int views() {

// Doesn't return any value.
void talkAboutVideo() {
// Printing something to the screen is different
// than returning a value.
IO.println(title() + " only has " + views() + " views.");
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Inside your `module-info.java` file you declare which packages are
"exported" from that module.

```java
```java,no_run
module reality {
exports earth;
exports sea;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/java.base.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ So if a file has the following

```java
void main() {
var names = ArrayList<String>();
var names = new ArrayList<String>();
names.add("Him");
names.add("Jim");
names.add("Bim");
Expand All @@ -39,7 +39,7 @@ import module java.base;

class Main {
void main() {
var names = ArrayList<String>();
var names = new ArrayList<String>();
names.add("Him");
names.add("Jim");
names.add("Bim");
Expand Down
8 changes: 4 additions & 4 deletions src/modules/purpose.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ want groupings of a grouping?
The answer is that[^more] when you share code with other people
you will often want to have that code contain multiple packages.
If you couldn't "hide" packages of code from the people using
the code you are sharing it would be a bummer.
the code you[^andby] are sharing it would be a bummer.

Just as private fields help you encapsulate state in a class
and package-private classes help you encapsulate whole classes,
unexported packages are your mechanism for encapsulating whole package.


[^andby]: And by "you" I mean you and whoever else is directly working with you.

[^more]: There are more answers, but they mostly involve tales of Java's past
and mistakes that were made there.
and mistakes that were made there.

[^andby]: And by "you" I mean you and whoever else is directly working with you.
2 changes: 1 addition & 1 deletion src/packages/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This will require marking the classes and many of the methods within `public`.

## Challenge 3.

Read through [the list of packages that come with Java](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/module-summary.html). You don't need to understand everything you are looking at; just
Read through [the list of packages that come with Java](https://javadoc.mccue.dev/api/java.base/module-summary.html). You don't need to understand everything you are looking at; just
browse and try to find at least one class that interests you.

Import that class and try to use it.
2 changes: 1 addition & 1 deletion src/reflection/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ as input and returns if the name of the underlying
class for that `Object` starts with a vowel.

You might need to consult the documentation
for [Class](https://docs.oracle.com/en/java/javase/25/docs/api/index.html).
for [Class](https://javadoc.mccue.dev/api/index.html).

```java,editable
class Apple {}
Expand Down
2 changes: 2 additions & 0 deletions src/return_values/void.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ int views() {

// Doesn't return any value.
void talkAboutVideo() {
// Printing something to the screen is different
// than returning a value.
IO.println(title() + " only has " + views() + " views.");
}

Expand Down
12 changes: 12 additions & 0 deletions src/standard_input/other_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ void main() {
char grade = Character.parseCharacter(gradeString);
IO.println("You have a " + grade + " in the class.");
}
```

For characters specifically you can get the first character of a `String` with `.charAt(0)`,
but you might also want to check that said `String` is only one character long. Each type
will be special.

```java,no_run
void main() {
String gradeString = IO.readln("What is your letter grade? ");
char grade = gradeString.charAt(0);
IO.println("You have a " + grade + " in the class.");
}
```
2 changes: 1 addition & 1 deletion src/static_methods/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ an instance of a class to call them would be silly.
The `Math` class that comes with Java has methods that work in this way. `Math.max(a, b)`
is `static` and therefore usable everywhere you want the maximum of two numbers.[^more]

[^more]: There are way more on there. [Take a look](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Math.html).
[^more]: There are way more on there. [Take a look](https://javadoc.mccue.dev/api/java.base/java/lang/Math.html).
2 changes: 1 addition & 1 deletion src/streams/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Main {

## Challenge 3.

Read the documentation on [`Collector`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/stream/Collector.html) and [`Collectors`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/stream/Collector.html).
Read the documentation on [`Collector`](https://javadoc.mccue.dev/api/java.base/java/util/stream/Collector.html) and [`Collectors`](https://javadoc.mccue.dev/api/java.base/java/util/stream/Collector.html).

Make an implementation of `Collector` that can collect elements into `MySpecialList`.

Expand Down
10 changes: 10 additions & 0 deletions src/streams/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ Stream<Integer> numberStream = numbers.stream()
.map(Integer::parseInt); // 1, 2, 3
```

You can also call `.map` multiple times to apply multiple transformations.

```java,no_run
var numbers = List.of("1", "2", "3");

Stream<Integer> numberStream = numbers.stream()
.map(Integer::parseInt) // 1, 2, 3
.map(x -> x * 2); // 2, 4, 6
```

[^metaphor]: In the real life stream metaphor, this is akin to rocks getting polished
by sand as they flow.

2 changes: 1 addition & 1 deletion src/time/date.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ class Main {

To be clear though, `Date` has problems. We aren't ready to explain all of them yet. Just treat `Date` as haunted, as in by ghosts, and use the `java.time` alternatives when you can.

[^gmt]: You will notice that when we print out the date we get GMT. GMT is basically the same as UTC, though [the documentation for `Date`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/Date.html) explains the difference.
[^gmt]: You will notice that when we print out the date we get GMT. GMT is basically the same as UTC, though [the documentation for `Date`](https://javadoc.mccue.dev/api/java.base/java/util/Date.html) explains the difference.