# Io / Github / Biezhi / Java11

## Overview

This area of the codebase appears to be a Java 11 feature tour. Rather than implementing a single business workflow, it groups together small, self-contained examples that demonstrate new or noteworthy language and platform capabilities in Java 11 and its nearby releases.

The sub-modules cover two broad themes:

- **Language features** such as `var`, updated interface capabilities, string helpers, immutable collection factories, try-with-resources refinements, and time conversions.
- **Platform APIs and runtime examples** such as file I/O, HTTP client usage, process inspection, and single-file execution.

Taken together, the package functions like a living notebook. Each sub-module isolates one concept, keeps the code minimal, and prints observable results so readers can see the feature in action.

## Sub-module Guide

### `collections`
This sub-module focuses on concise collection construction. It demonstrates immutable factories like `List.of`, `Map.of`, `Map.ofEntries`, `Map.entry`, and `Set.of`, and also shows the diamond operator with a generic anonymous subclass.

Relationship-wise, this package is about **object creation style**: it teaches how to build values with less ceremony and how generics behave when an inline implementation is needed. It pairs well with `var`, because both examples are about reducing local syntactic noise without changing the underlying types.

### `files`
This sub-module demonstrates the basic lifecycle of a text file with `Files.writeString`, `Files.readString`, and `Files.delete`.

It acts as the simplest I/O example in the area and provides a useful foundation for the more advanced file interactions in `http` and `trywithresources`. In other words, this module shows the core file round-trip that other examples rely on or extend.

### `http`
This sub-module is the most expansive example in the package. It demonstrates synchronous and asynchronous HTTP requests, JSON POST bodies, file downloads and uploads, proxy configuration, basic authentication, HTTP/2 selection, and coordinated fan-out requests.

It connects the rest of the system together by combining several standard APIs: networking, concurrency, JSON serialization, and file handling. If the other modules are single-feature demos, `http` is the integration-style example that shows how those features can be combined in one client workflow.

### `interfaces`
This sub-module demonstrates interface evolution: an abstract method, default methods, private helper methods, and a private static helper.

It is mainly about **encapsulation inside interfaces**. The default methods share logic through a private helper so the public interface stays small while the repeated behavior remains centralized. This makes it a conceptual companion to the collection and string examples, which also emphasize API convenience and code reuse.

### `processor`
This sub-module is a minimal Process API example. It obtains the current `ProcessHandle` and prints the current PID.

It is the smallest runtime-introspection example in the package set. While it does not coordinate with other sub-modules, it fits the same overall pattern: use a focused example to expose one platform capability clearly.

### `singlefile`
This sub-module shows how a source file can be launched directly as a single-file program. The example simply prints a greeting.

It is less about application logic and more about how Java 11 can reduce the ceremony required to run code. This makes it a practical companion to the other examples: the code is intentionally tiny so the execution model itself becomes the lesson.

### `string`
This sub-module demonstrates newer `String` APIs such as `repeat`, `lines`, `strip`, `stripLeading`, `stripTrailing`, and `isBlank`.

This package is one of the clearest examples of the area’s teaching style: each method isolates a specific API and prints output that makes the behavior obvious. It relates to `var` and `collections` because they all emphasize reduced boilerplate and more expressive standard-library APIs.

### `time`
This sub-module bridges modern `java.time.Duration` values with `TimeUnit` conversions.

It is a narrow but practical example: it shows how code can translate between a newer time abstraction and older timeout-oriented APIs. That makes it useful as an interop reference for code that sits between modern date/time handling and legacy concurrency utilities.

### `trywithresources`
This sub-module demonstrates try-with-resources using an already-created reader variable. It reads and prints the contents of `./README.md`.

This example is about resource lifecycle management, and it complements `files` by showing how file access can be wrapped in automatic cleanup. It also fits the broader theme of language feature refinements: the code is small, but the syntax shows an updated style of writing safer I/O code.

### `var`
This sub-module focuses on local variable type inference. It shows `var` with collections, streams, file paths, byte arrays, enhanced for-loops, and try-with-resources.

It is the clearest “syntax simplification” example in the package. Conceptually, it ties together many of the other modules because it appears wherever local declarations are getting in the way of the underlying API being demonstrated.

## Key Patterns and Architecture

These examples share a common architecture:

1. **One concept per class or method** — each package isolates a single Java feature or API family.
2. **Console-first feedback** — the examples print results rather than returning rich objects or integrating with a larger application.
3. **Minimal state** — most examples create a value, use it immediately, and discard it.
4. **Standard-library centric design** — the modules mostly depend on JDK classes instead of framework abstractions.

This makes the package set behave like an educational reference library rather than a service layer. The code does not appear to be composed into a larger runtime system; instead, each example is independently executable and easy to inspect.

A useful way to think about the architecture is:

- `collections`, `string`, `time`, `interfaces`, `trywithresources`, and `var` explain **language and API surface area**.
- `files`, `http`, `processor`, and `singlefile` explain **how those features behave in real runtime contexts**.

The examples are intentionally short, but they still model common patterns such as factory-based construction, default-method reuse, round-trip file verification, request/response flows, and resource cleanup.

## Dependencies and Integration

This package set appears to rely mostly on the Java standard library, with one notable external dependency in the HTTP examples.

### Standard JDK usage
- `java.util` collection factories and generic types
- `java.lang.String` enhancements
- `java.nio.file.Files`, `Path`, and `Paths`
- `java.net.http.HttpClient`, `HttpRequest`, and `HttpResponse`
- `java.time.Duration`
- `java.util.concurrent.TimeUnit` and `CompletableFuture`
- `java.lang.ProcessHandle`
- `java.io` readers and streams

### External library usage
- The `http` module uses `com.google.gson.Gson` for JSON serialization.

### Integration style
These modules do not appear to depend on one another through code-level imports or runtime orchestration. Instead, they are linked conceptually by theme:

- file I/O supports the HTTP upload/download examples,
- `var` reduces declaration noise in several demonstrations,
- string and collection factories make the examples shorter and easier to read,
- try-with-resources and process inspection show everyday Java runtime patterns.

## Mermaid Diagram

```mermaid
flowchart TD
  Root["Io / Github / Biezhi / Java11"] --> LanguageFeatures["Language features"]
  Root --> IOExamples["I/O and platform APIs"]
  LanguageFeatures --> Collections["collections"]
  LanguageFeatures --> Interfaces["interfaces"]
  LanguageFeatures --> StringPkg["string"]
  LanguageFeatures --> TimePkg["time"]
  LanguageFeatures --> TryWithResources["trywithresources"]
  LanguageFeatures --> VarPkg["var"]
  IOExamples --> FilesPkg["files"]
  IOExamples --> HttpPkg["http"]
  IOExamples --> ProcessorPkg["processor"]
  IOExamples --> SingleFilePkg["singlefile"]
  Collections --> ImmutableFactories["Immutable factory methods"]
  Collections --> DiamondOperator["Diamond operator"]
  HttpPkg --> HttpClient["HttpClient demos"]
  HttpPkg --> FooModel["Foo payload model"]
```

## Notes for Developers

- This area appears to be documentation-friendly by design: the examples are small enough that the behavior is visible without reading many files.
- The examples usually trade completeness for clarity. For example, several classes print directly to standard output and do not include robust error handling.
- Some modules rely on external conditions: `http` needs reachable endpoints, `files` writes to the working directory, and `trywithresources` expects `./README.md` to exist.
- The collection and interface examples are especially useful for understanding API shape and language rules, while the I/O examples are better for understanding runtime behavior.
- If you extend this area, it would make sense to preserve the current pattern of one feature demonstration per class or method so the package remains easy to scan.

## Dependencies at a Glance

- [`collections`](.codewiki/io/github/biezhi/java11/collections.md)
- [`files`](.codewiki/io/github/biezhi/java11/files.md)
- [`http`](.codewiki/io/github/biezhi/java11/http.md)
- [`interfaces`](.codewiki/io/github/biezhi/java11/interfaces.md)
- [`processor`](.codewiki/io/github/biezhi/java11/processor.md)
- [`singlefile`](.codewiki/io/github/biezhi/java11/singlefile.md)
- [`string`](.codewiki/io/github/biezhi/java11/string.md)
- [`time`](.codewiki/io/github/biezhi/java11/time.md)
- [`trywithresources`](.codewiki/io/github/biezhi/java11/trywithresources.md)
- [`var`](.codewiki/io/github/biezhi/java11/var.md)
