# Getting Started

This repository is a compact Java 11 examples project. It is organized as a set of small, runnable demos that each highlight one language feature or standard-library API. If you are new here, the fastest way to get oriented is to read the examples package by package rather than looking for a single application flow.

## What This Project Does

The project demonstrates Java 11 features such as `var`, immutable collections, the HTTP client, `String` helpers, `Files` APIs, try-with-resources, time conversions, private interface methods, and single-file execution. Most code lives in self-contained example classes that print output or perform tiny file/network operations, so the repository works best as a learning reference and a cookbook of small samples.

## Recommended Reading Order

Start with the overview page, then move through the examples in this order:

1. [`overview.md`](../overview.md) — big-picture map of the repository and its modules.
2. [`var/Example`](../../src/main/java/io/github/biezhi/java11/var/Example.java) — best first read for the project’s style and Java 11 local type inference.
3. [`string/Example`](../../src/main/java/io/github/biezhi/java11/string/Example.java) and [`collections/Example`](../../src/main/java/io/github/biezhi/java11/collections/Example.java) — common Java 11 language and collection conveniences.
4. [`files/Example`](../../src/main/java/io/github/biezhi/java11/files/Example.java) and [`trywithresources/Example`](../../src/main/java/io/github/biezhi/java11/trywithresources/Example.java) — file handling and resource cleanup.
5. [`http/Example`](../../src/main/java/io/github/biezhi/java11/http/Example.java) and [`http/Foo`](../../src/main/java/io/github/biezhi/java11/http/Foo.java) — the most feature-rich example in the repo.
6. The smaller feature demos: [`interfaces/Example`](../../src/main/java/io/github/biezhi/java11/interfaces/Example.java), [`processor/Example`](../../src/main/java/io/github/biezhi/java11/processor/Example.java), [`time/Example`](../../src/main/java/io/github/biezhi/java11/time/Example.java), and [`singlefile/HelloWorld`](../../src/main/java/io/github/biezhi/java11/singlefile/HelloWorld.java).

## Key Entry Points

There are no highly connected classes in this codebase, so the best entry points are the example files themselves:

- [`var/Example`](../../src/main/java/io/github/biezhi/java11/var/Example.java) — local variable inference across collections, streams, paths, and try-with-resources.
- [`string/Example`](../../src/main/java/io/github/biezhi/java11/string/Example.java) — `String` utilities like `lines`, `strip`, and `isBlank`.
- [`collections/Example`](../../src/main/java/io/github/biezhi/java11/collections/Example.java) — immutable collection factories and related helpers.
- [`collections/DiamondOperatorExample`](../../src/main/java/io/github/biezhi/java11/collections/DiamondOperatorExample.java) — diamond operator behavior in anonymous classes.
- [`files/Example`](../../src/main/java/io/github/biezhi/java11/files/Example.java) — simple read/write/delete file flow.
- [`http/Example`](../../src/main/java/io/github/biezhi/java11/http/Example.java) — Java 11 HTTP client patterns, including async and file transfer examples.
- [`http/Foo`](../../src/main/java/io/github/biezhi/java11/http/Foo.java) — small DTO used by the HTTP JSON example.
- [`interfaces/Example`](../../src/main/java/io/github/biezhi/java11/interfaces/Example.java) — interface defaults and private methods.
- [`processor/Example`](../../src/main/java/io/github/biezhi/java11/processor/Example.java) — `ProcessHandle` basics.
- [`time/Example`](../../src/main/java/io/github/biezhi/java11/time/Example.java) — duration and time-unit conversion.
- [`trywithresources/Example`](../../src/main/java/io/github/biezhi/java11/trywithresources/Example.java) — resource cleanup with a buffered reader.
- [`singlefile/HelloWorld`](../../src/main/java/io/github/biezhi/java11/singlefile/HelloWorld.java) — minimal runnable sample.

## Project Structure

Source code is grouped under `src/main/java/io/github/biezhi/java11/`, with one subpackage per Java feature area:

- `collections/` — collection factory and generics examples
- `files/` — file I/O samples
- `http/` — HTTP client examples and DTOs
- `interfaces/` — interface default/private method examples
- `processor/` — process inspection examples
- `singlefile/` — single-file launch demo
- `string/` — modern `String` APIs
- `time/` — `Duration` and `TimeUnit` examples
- `trywithresources/` — resource-management examples
- `var/` — local variable inference examples

```mermaid
flowchart TD
Start["Start here"] --> Var["var/Example"]
Var --> String["string/Example"]
String --> Collections["collections/Example"]
Collections --> Files["files/Example"]
Files --> Try["trywithresources/Example"]
Try --> Http["http/Example and http/Foo"]
Http --> Interfaces["interfaces/Example"]
Interfaces --> Processor["processor/Example"]
Processor --> Time["time/Example"]
Time --> Singlefile["singlefile/HelloWorld"]
```

Each package is intentionally small and independent. You usually do not need to trace dependencies across packages; instead, read the example class that matches the feature you want to learn.

## Configuration

The main build file is [`pom.xml`](../../pom.xml). It controls:

- the Maven coordinates for the project (`io.github.biezhi:java11-examples`)
- the Java release level (`11`)
- the only declared third-party dependency, `com.google.code.gson:gson:2.8.5`
- the test/runtime compiler setup, including `maven-surefire-plugin` with `--add-modules=jdk.incubator.httpclient`

Other notable repository files:

- [`src/jenkinsfile`](../../src/jenkinsfile) — CI-related pipeline configuration
- [`README.md`](../../README.md) — top-level project summary
- [`.gitignore`](../../.gitignore) — ignored build and local files

## Common Patterns

The code follows a few simple conventions throughout:

- **One concept per file** — each example focuses on a single Java 11 feature.
- **Runnable snippets** — many examples are designed to be executed directly from `main` or a small demo method.
- **Console output over abstractions** — behavior is often shown by printing results instead of building reusable APIs.
- **Standard library first** — most modules use only JDK classes; `http/` is the main place that adds Gson.
- **Minimal cross-package coupling** — packages are meant to be read independently.
- **Feature-name package layout** — package names match the topic they demonstrate, which makes navigation straightforward.

## Practical Next Steps

If you only have 15 minutes, read `overview.md`, then open `var/Example` and `http/Example`. Those two files give you the best sense of the project’s style range: one is a small language-feature sample, and the other is the most complete API demo in the repository.
