I/O Intermediate

Parse and compose resource identifiers as URI values before converting to URL when necessary.

✕ Deprecated URL constructor
URL endpoint =
    new URL("https://example.com/api?q=java");
✓ Java 20+
URI endpointUri =
    URI.create("https://example.com/api?q=java");
URL endpoint = endpointUri.toURL();
See a problem with this code? Let us know.

Avoids deprecation

Removes use of deprecated URL constructors.

🧠

Predictable semantics

URI comparison does not perform network-dependent resolution.

🧩

Better composition

URI is designed for parsing and manipulating identifiers.

Old Approach
Direct URL construction
Modern Approach
URI then URL
Since JDK
20
Difficulty
Intermediate
Deprecated URL constructors to URI
Available

URL constructors deprecated since JDK 20 (March 2023)

URL constructors were deprecated in JDK 20 because URL parsing and equality have surprising protocol-handler behavior. URI is the preferred immutable representation for parsing, composition, comparison, and normalization; convert only at APIs that require URL.