# Io / Github / Biezhi / Java11

## Overview

This package appears to be a Java 11 feature tour rather than a production subsystem. Across its child modules, it demonstrates small, runnable examples of language and JDK APIs: immutable collections, file I/O, the HTTP client, interface defaults and private methods, process inspection, single-file launch, updated `String` utilities, time conversion, try-with-resources refinements, and local variable type inference with `var`.

Taken together, the area functions as a living reference for modern Java 11 idioms. The samples are intentionally narrow and console-driven, so the focus stays on syntax, API shape, and runtime behavior instead of domain logic.

## Sub-module Guide

The child modules form a set of independent demonstrations, but they share a common design style: each one isolates a Java 11 capability in a small `Example`-style entry point.

- **[collections](.codewiki/io/github/biezhi/java11/collections.md)** — Shows immutable collection factories such as `List.of()`, `Map.of()`, `Map.ofEntries()`, and `Set.of()`, plus diamond-operator inference with anonymous generic subclasses.
  - This module complements `var` by showing how inferred local types behave when the values come from modern factory methods.
  - It is the most data-structure-oriented sample in the package.

- **[files](.codewiki/io/github/biezhi/java11/files.md)** — Demonstrates the `Files` API by writing, reading, comparing, and deleting a text file.
  - It provides the simplest persistence-style workflow in the package and is a natural baseline for the more advanced file-adjacent examples.

- **[http](.codewiki/io/github/biezhi/java11/http.md)** — Showcases the Java 11 `HttpClient` with synchronous and asynchronous requests, file download/upload, proxy support, basic auth, HTTP/2, and parallel fan-out.
  - This is the most integration-heavy child module because it combines networking, concurrency, file handling, and JSON serialization.
  - It builds on ideas also seen in `files` and `var`, but applies them to remote communication.

- **[interfaces](.codewiki/io/github/biezhi/java11/interfaces.md)** — Demonstrates interface evolution: abstract methods, default methods, private instance helpers, and private static helpers.
  - This module is about API design boundaries rather than runtime workflows.
  - It complements the other modules by showing how Java 11 supports encapsulation inside interface definitions themselves.

- **[processor](.codewiki/io/github/biezhi/java11/processor.md)** — Uses `ProcessHandle` to print the current JVM process ID.
  - This is a small runtime-introspection example and is conceptually adjacent to other system-level utilities in the package.

- **[singlefile](.codewiki/io/github/biezhi/java11/singlefile.md)** — Demonstrates single-file source execution by defining a tiny `HelloWorld` class.
  - This is the lightest-weight entry point in the package and serves as a workflow example rather than a library example.

- **[string](.codewiki/io/github/biezhi/java11/string.md)** — Explores Java 11 `String` improvements such as `lines()`, `strip()`, `stripLeading()`, `stripTrailing()`, `isBlank()`, and `repeat()`.
  - This module acts as a shared utility showcase because string handling appears throughout the rest of the package’s console output and sample payloads.

- **[time](.codewiki/io/github/biezhi/java11/time.md)** — Demonstrates conversion between `Duration` and `TimeUnit`.
  - It is a narrow but useful example of bridging modern time APIs with older concurrency-oriented utilities.

- **[trywithresources](.codewiki/io/github/biezhi/java11/trywithresources.md)** — Shows try-with-resources using an existing `BufferedReader` variable.
  - This module is especially relevant to file-oriented code because it demonstrates a cleanup pattern that file and stream examples depend on conceptually.

- **[var](.codewiki/io/github/biezhi/java11/var.md)** — Demonstrates local variable type inference across collections, streams, file paths, byte arrays, loops, and resource declarations.
  - This appears to be the connective tissue of the package: many of the other modules rely on the same modern Java style, and `var` explains how those types are inferred in practice.

### How the modules relate

The package is best understood as a set of feature slices around a shared teaching goal:

- **Core language features** are covered by `interfaces`, `collections`, `string`, and `var`.
- **I/O and runtime interaction** are covered by `files`, `trywithresources`, and `processor`.
- **Networked and external interaction** is covered by `http`.
- **Developer workflow** is covered by `singlefile`.
- **Cross-cutting time handling** is covered by `time`.

This appears to be organized so a reader can learn one Java 11 capability at a time without needing to understand a larger application architecture first.

## Key Patterns and Architecture

### Example-driven architecture

Each sub-module is structured as a self-contained executable sample rather than a reusable library. That creates a consistent pattern:

1. Declare a minimal class or interface.
2. Use a single entry point or a small set of methods.
3. Print the result directly to standard output.
4. Keep the scope narrow enough that the API behavior is easy to observe.

This style reduces interdependence between modules and makes the package easy to scan as documentation.

### Language-feature isolation

The samples tend to isolate one Java feature at a time:

- `collections` isolates immutable factory methods and diamond inference.
- `string` isolates post-Java-8 string convenience methods.
- `var` isolates local type inference in several different syntactic positions.
- `interfaces` isolates private interface methods and default-method reuse.

That pattern suggests the module is meant to be read incrementally, with each child page teaching one concept before moving to the next.

### Console-first feedback loop

Most modules produce visible output rather than returning structured data. That makes the flow easy to understand:

- input or sample values are created inline,
- a JDK API is invoked,
- the result is printed or compared,
- cleanup happens if needed.

The file, HTTP, and try-with-resources examples especially rely on this pattern to make side effects obvious.

### Resource and lifecycle awareness

Several modules emphasize lifecycle handling:

- `files` writes then deletes a temporary file.
- `trywithresources` demonstrates automatic closure of an existing reader.
- `http` uses `.join()` to keep asynchronous examples alive long enough to complete.

This appears to be deliberate: even though the package is mostly educational, it still shows how Java 11 manages resources and asynchronous completion.

## Dependencies and Integration

### External dependencies observed in the child modules

Most child modules depend only on the JDK, but `http` introduces one third-party library:

- **JDK standard library** — Used throughout the package for collections, I/O, time, strings, process inspection, and concurrency.
- **Gson** — Used in `http` to serialize a small DTO before POSTing JSON.

### Integration points within the package

The modules are largely independent and no cross-module links were detected in the index. Even so, they cluster around a few shared concerns:

- **File-oriented flows**: `files`, `trywithresources`, and parts of `http`.
- **Type inference and syntax**: `collections`, `string`, and `var`.
- **Runtime introspection**: `processor` and `singlefile`.
- **Networking and external services**: `http`.

This means the package integrates primarily through shared learning themes, not through code dependencies.

## Mermaid Diagram

```mermaid
flowchart TD
Java11Root["io.github.biezhi.java11"] --> Collections["collections"]
Java11Root --> Files["files"]
Java11Root --> Http["http"]
Java11Root --> Interfaces["interfaces"]
Java11Root --> Processor["processor"]
Java11Root --> Singlefile["singlefile"]
Java11Root --> StringModule["string"]
Java11Root --> Time["time"]
Java11Root --> TryWithResources["trywithresources"]
Java11Root --> Var["var"]
Http --> Files
Http --> StringModule
Http --> Var
Files --> TryWithResources
Collections --> Var
Interfaces --> StringModule
```

## Notes for Developers

- Treat these modules as documentation code. Their primary goal is to demonstrate Java 11 behavior, not to provide reusable application services.
- Several examples rely on hard-coded environment assumptions such as local file paths, external URLs, or demo credentials. Those assumptions are fine for teaching but should be reviewed before reuse.
- The examples often print directly to stdout, which keeps them simple but means they are not structured for composition.
- `var` and immutable factory methods are recurring themes. When extending the package, try to keep the examples consistent with that style so the codebase remains a coherent Java 11 reference.
- Some child pages describe methods that are intentionally not called from `main`. This appears to be a teaching choice so each API can be shown independently.
- Because no source files were indexed at the parent level, the child documentation is the best map for understanding the area’s behavior.
