Skip to content

Commit 0bfdffd

Browse files
committed
[J17] Add manual loading (j17style) example description
1 parent 327da01 commit 0bfdffd

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
162 KB
Loading
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## Java 17. Manual Loading (Java 17 style)
2+
---
3+
**Task:** load any application class using a custom class loader (`CustomClassLoader`) in Java 17 style (with `module-info.java`).
4+
5+
### Solution
6+
---
7+
Modules (declared via `module-info.java`):
8+
- `manual.onemodule.j17style`:
9+
- [`Main`](src/ru/ispras/j17/manual/onemodule/j8style/Main.java) - a class containing the `main` method, where an instance of the `CustomClassLoader` class is created, the `Cat` class is loaded using it, creating an instance of the class `Cat` and calling the `Cat::talk` method;
10+
- [`Cat`](src/ru/ispras/j17/manual/onemodule/j8style/Cat.java) - loadable class with the `talk` method, which prints the string *"Meow"* to `stdout`;
11+
- [`CustomClassLoader`](src/ru/ispras/j17/manual/onemodule/j8style/CustomClassLoader.java) - a class that is an implementation of a custom class loader.
12+
13+
### Run
14+
---
15+
> Using `classpath` the results are the same as in [[Java 17. Manual Loading (Java 8 style)]].
16+
17+
Using `modulepath`:
18+
19+
```shell
20+
java17 -p . -m manual.onemodule.j17style
21+
```
22+
23+
Output:
24+
25+
```shell
26+
Main Class Module is module manual.onemodule.j17style
27+
Cat Class Module is unnamed module @f6f4d33
28+
Main Class ClassLoader is jdk.internal.loader.ClassLoaders$AppClassLoader@4554617c
29+
Cat Class ClassLoader is ru.ispras.j17.manual.onemodule.j17style.CustomClassLoader@5acf9800
30+
Meow
31+
```
32+
33+
### Explanation
34+
---
35+
![Java 17. Manual Loading (Java 17 style).jpg](../../../../img/Java%2017.%20Manual%20Loading%20(Java%2017%20style).jpg)
36+
37+
- Regarding [[Java 17. Manual Loading (Java 8 style)|Java 17. Manual Loading (Java 8 style)]] is different with the module name `manual.onemodule.j17style` in the `jar` file, which is anchored with `module-info .java`, so this module is considered an **Application Module**, and not an **Automatic Module**.
38+
39+
### Notes
40+
---
41+
*Same as in [[Java 17. Manual Loading (Java 8 style)|Java 17. Manual Loading (Java 8 style)]]*.

0 commit comments

Comments
 (0)