Skip to content

Commit 4a22e72

Browse files
committed
Java doc
1 parent 9a3714b commit 4a22e72

File tree

5 files changed

+137
-8
lines changed

5 files changed

+137
-8
lines changed

src/SUMMARY.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -890,16 +890,16 @@ Make them do one. -->
890890

891891
# Sharing Code II
892892

893+
<!--
894+
TODO: Wait for hermetic java
893895
- [Distribution](./distribution.md)
894896
- [jars](./distribution/jars.md)
895-
- [jlink]()
897+
- [jlink]() -->
896898
- [Documentation](./documentation.md)
897899
- [Documentation Comments](./documentation/documentation_comments.md)
898-
- [javadoc]()
899-
- [@param]()
900-
- [@return]()
901-
- [@throws]()
902-
- [Markdown]()
900+
- [Format](./documentation/format.md)
901+
- [javadoc](./documentation/javadoc.md)
902+
- [Challenges](./documentation/challenges.md)
903903

904904

905905
<!---

src/documentation/challenges.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Challenges
2+
3+
Remember the rules for this are
4+
5+
- Try to use only the information given up to this point in this book.
6+
- Try not to give up until you've given it a solid attempt
7+
8+
## Challenge 1.
9+
10+
Run `javadoc` on some of your code. Add the command for doing so to a `Justfile`.
11+
Make sure to include cleaning stale of output.
12+
13+
## Challenge 2.
14+
15+
When you ran `javadoc` on your code you were almost certainly hit by a deluge of `warning: no comment`
16+
messages.
17+
18+
Fix these by documenting that code enough that `javadoc` no longer gives you warnings.
19+
20+
## Challenge 3.
21+
22+
Read the [documentation for java.util.StringJoiner](https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/util/StringJoiner.html).
23+
24+
If you can, alter one of your projects to use it.

src/documentation/documentation_comments.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ You put these documentation comments above different elements of your program
99
with text describing what the purpose of those elements are.
1010

1111
```java
12-
/// This class represents the i
12+
/// This class represents a ninja
1313
public class Ninja {
14-
14+
/// Says a catchphrase
15+
public void forsooth() {
16+
// ..
17+
}
1518
}
1619
```
1720

src/documentation/format.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Format
2+
3+
```java,no_run
4+
import java.io.IOException;
5+
6+
/// This class serves as a place to put examples
7+
/// of the different kinds of documentation as well
8+
/// as how to write documentation properly.
9+
///
10+
/// When specified after the three slashes
11+
/// you can write documentation using [Markdown](https://en.wikipedia.org/wiki/Markdown).
12+
///
13+
/// In Markdown you can just write text as you would in any file,
14+
/// line after line.
15+
///
16+
/// # For headings you can use a single hash
17+
///
18+
/// ## For subheadings you can use two
19+
///
20+
/// ### And so on
21+
///
22+
/// You can make unordered lists using hyphens
23+
///
24+
/// - A
25+
/// - B
26+
/// - C
27+
///
28+
/// And numbered lists like so
29+
///
30+
/// 1. One
31+
/// 2. Two
32+
/// 3. Thre
33+
///
34+
/// And so on. Definitely peruse up [tutorial on markdown](https://www.markdownguide.org/getting-started/)
35+
/// when you have the time.
36+
///
37+
/// There are some additions specific to Java though.
38+
/// We call these additions "tags."
39+
///
40+
/// One notable tag is the author tag. It lets you mark who worked
41+
/// on a given unit of code
42+
///
43+
/// @author Ethan McCue
44+
/// @see [https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html](https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html)
45+
public class DocumentationExample {
46+
/// You can document the purpose of parameters
47+
/// to constructors and methods with the param tag
48+
///
49+
/// @param o Demonstrates a param tag on a constructor
50+
public DocumentationExample(Object o) {
51+
52+
}
53+
54+
/// Generic parameters can also be documented using the param tag
55+
/// as well.
56+
///
57+
/// @param item The item to just return back
58+
/// @param <T> The type of the item.
59+
public static <T> T identity(T item) {
60+
return item;
61+
}
62+
63+
/// The exceptions thrown by a method can also be documented
64+
/// to explain under what conditions the exceptions might be thrown
65+
///
66+
/// @param s A parameter to show that throws can be used alongside params
67+
/// @throws IOException whenever the method is called, no matter what
68+
public void crash(String s) throws IOException {
69+
throw new IOException();
70+
}
71+
72+
/// You can reference other classes and methods on those classes with the
73+
/// link tag.
74+
///
75+
/// For instance {@link String} and {@link String#length()}.
76+
public void seeMore() {
77+
78+
}
79+
}
80+
```

src/documentation/javadoc.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# javadoc
2+
3+
The way to take code with documentation comments and produce a documentation website
4+
is with the `javadoc` tool.
5+
6+
There are multiple ways to run this[^theme], but if you have your code in the
7+
multi-module directory layout you can use `--module-path` and `--module` the
8+
same as `javac` does.
9+
10+
```bash,no_run
11+
javadoc \
12+
-d output/javadoc \
13+
--module-source-path "./*/src" \
14+
--module one.piece
15+
```
16+
17+
This will produce a directory full of HTML files that contain all
18+
the documentation from the specified modules.
19+
20+
This is what is used to make [the official Java documenation](https://docs.oracle.com/en/java/javase/24/docs/api/index.html) as well as at least part of the documentation for most Java libraries.
21+
22+
[^theme]: As is a theme with command-line tools

0 commit comments

Comments
 (0)