Skip to content

Commit 774d7ee

Browse files
committed
Merge remote-tracking branch 'origin/main' into brunoborges-websocket-client-pattern
# Conflicts: # content/io/http-client.yaml # content/io/io-class-console-io.yaml
2 parents 50b3f76 + 355ce20 commit 774d7ee

19 files changed

Lines changed: 320 additions & 9 deletions
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
id: d54a4e9f-74b9-4579-84a3-2541fe7b4272
3+
slug: "legacy-synchronized-collections"
4+
title: "Legacy synchronized collections to modern alternatives"
5+
category: "collections"
6+
difficulty: "intermediate"
7+
jdkVersion: "5"
8+
oldLabel: "Legacy synchronized collection"
9+
modernLabel: "Concurrent Collections API"
10+
oldApproach: "Hashtable"
11+
modernApproach: "ConcurrentHashMap"
12+
oldCode: |-
13+
Hashtable<String, Session> sessions = new Hashtable<>();
14+
sessions.put(id, session);
15+
modernCode: |-
16+
ConcurrentMap<String, Session> sessions = new ConcurrentHashMap<>();
17+
sessions.put(id, session);
18+
summary: "Replace Vector and Hashtable with collections selected for actual mutability and concurrency needs."
19+
explanation: "Vector and Hashtable synchronize every operation through legacy APIs. Modern\
20+
\ code should normally use ArrayList or HashMap for thread-confined data, and purpose-built\
21+
\ concurrent collections when shared mutation is required."
22+
whyModernWins:
23+
- icon: "🎯"
24+
title: "Intentional concurrency"
25+
desc: "The chosen type documents whether sharing is expected."
26+
- icon: "⚡"
27+
title: "Better scalability"
28+
desc: "ConcurrentHashMap avoids a single table-wide lock for normal access."
29+
- icon: "🧩"
30+
title: "Modern APIs"
31+
desc: "Works naturally with current collection and concurrent-map operations."
32+
support:
33+
state: "available"
34+
description: "Widely available since JDK 5 (September 2004)"
35+
prev: "collections/unmodifiable-collectors"
36+
next: "strings/string-isblank"
37+
related:
38+
- "collections/immutable-map-creation"
39+
- "collections/copying-collections-immutably"
40+
- "concurrency/lock-free-lazy-init"
41+
tags:
42+
- collections
43+
- concurrency
44+
docs:
45+
- title: "ConcurrentHashMap"
46+
href: "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/ConcurrentHashMap.html"
47+
- title: "ConcurrentMap"
48+
href: "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/ConcurrentMap.html"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
id: 5ec6dc04-e96e-4d30-a11c-ea48c9d28fbf
3+
slug: "stack-to-deque"
4+
title: "Stack to Deque and ArrayDeque"
5+
category: "collections"
6+
difficulty: "beginner"
7+
jdkVersion: "6"
8+
oldLabel: "Legacy Stack"
9+
modernLabel: "Deque API"
10+
oldApproach: "Stack"
11+
modernApproach: "Deque with ArrayDeque"
12+
oldCode: |-
13+
Stack<String> stack = new Stack<>();
14+
stack.push("task");
15+
String next = stack.pop();
16+
modernCode: |-
17+
Deque<String> stack = new ArrayDeque<>();
18+
stack.push("task");
19+
String next = stack.pop();
20+
summary: "Use the Deque interface with ArrayDeque instead of the legacy Stack class."
21+
explanation: "Stack extends the legacy synchronized Vector class. Deque models stack operations directly, and ArrayDeque is the preferred general-purpose implementation for in-memory LIFO work."
22+
whyModernWins:
23+
- icon: "🎯"
24+
title: "Better abstraction"
25+
desc: "Deque explicitly models both stack and queue operations."
26+
- icon: "⚡"
27+
title: "Lower overhead"
28+
desc: "ArrayDeque avoids Vector's legacy synchronization."
29+
- icon: "🧩"
30+
title: "More flexible"
31+
desc: "The same interface supports LIFO and FIFO algorithms."
32+
support:
33+
state: "available"
34+
description: "Available since JDK 6 (December 2006)"
35+
prev: "enterprise/spring-boot-mvc-config"
36+
next: null
37+
related:
38+
- "collections/sequenced-collections"
39+
- "collections/reverse-list-iteration"
40+
- "collections/immutable-list-creation"
41+
tags:
42+
- collections
43+
docs:
44+
- title: "Deque (Java 25)"
45+
href: "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/Deque.html"
46+
- title: "ArrayDeque (Java 25)"
47+
href: "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/ArrayDeque.html"
48+
- title: "Stack (Java 25)"
49+
href: "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/Stack.html"

‎content/collections/unmodifiable-collectors.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ support:
3636
state: "available"
3737
description: "Widely available since JDK 16 (March 2021)"
3838
prev: "collections/reverse-list-iteration"
39-
next: "strings/string-isblank"
39+
next: "collections/legacy-synchronized-collections"
4040
related:
4141
- "collections/immutable-map-creation"
4242
- "collections/immutable-set-creation"

‎content/datetime/hex-format.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ support:
4141
state: "available"
4242
description: "Widely available since JDK 17 LTS (Sept 2021)"
4343
prev: "datetime/math-clamp"
44-
next: "security/pem-encoding"
44+
next: "datetime/locale-of"
4545
related:
4646
- "datetime/date-formatting"
4747
- "datetime/instant-precision"

‎content/datetime/locale-of.yaml‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
id: 361b53ba-ec9d-45a1-95e5-8c4b3aa7731a
3+
slug: "locale-of"
4+
title: "Locale constructors to Locale.of()"
5+
category: "datetime"
6+
difficulty: "beginner"
7+
jdkVersion: "19"
8+
oldLabel: "Deprecated constructor"
9+
modernLabel: "Java 19+"
10+
oldApproach: "Locale constructors"
11+
modernApproach: "Locale.of()"
12+
oldCode: |-
13+
Locale brazilianPortuguese =
14+
new Locale("pt", "BR");
15+
modernCode: |-
16+
Locale brazilianPortuguese =
17+
Locale.of("pt", "BR");
18+
summary: "Create language and region locales with Locale.of() instead of deprecated constructors."
19+
explanation: "Locale factory methods replace constructors deprecated in JDK 19. The factory\
20+
\ form is clearer, aligns with other value-based APIs, and centralizes locale creation."
21+
whyModernWins:
22+
- icon: "✅"
23+
title: "Supported API"
24+
desc: "Avoids deprecated constructors."
25+
- icon: "👁"
26+
title: "Clear construction"
27+
desc: "The named factory communicates intent."
28+
- icon: "🧩"
29+
title: "Consistent style"
30+
desc: "Matches modern JDK value-object factories."
31+
support:
32+
state: "available"
33+
description: "Available since JDK 19 (September 2022)"
34+
prev: "datetime/hex-format"
35+
next: "security/pem-encoding"
36+
related:
37+
- "datetime/date-formatting"
38+
- "datetime/java-time-basics"
39+
- "strings/string-formatted"
40+
tags:
41+
- datetime
42+
- constructors
43+
docs:
44+
- title: "Locale.of()"
45+
href: "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/Locale.html#of(java.lang.String,java.lang.String)"

‎content/enterprise/spring-boot-mvc-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ support:
4444
state: "available"
4545
description: "Available in Spring Boot 4.0 with Spring Framework 7.0 (requires Java 17+)"
4646
prev: "enterprise/spring-null-safety-jspecify"
47-
next: null
47+
next: "collections/stack-to-deque"
4848
related:
4949
- "enterprise/spring-api-versioning"
5050
- "enterprise/spring-xml-config-vs-annotations"

‎content/io/http-websocket-client.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ support:
4949
state: "available"
5050
description: "Widely available since JDK 11 (September 2018)"
5151
prev: "io/http-client"
52-
next: "io/io-class-console-io"
52+
next: "io/url-constructors-to-uri"
5353
related:
5454
- "io/http-client"
5555
- "concurrency/completablefuture-chaining"

‎content/io/io-class-console-io.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ whyModernWins:
4343
support:
4444
state: "available"
4545
description: "Finalized in JDK 25 alongside compact source files (JEP 512)"
46-
prev: "io/http-websocket-client"
46+
prev: "io/url-constructors-to-uri"
4747
next: "io/reading-files"
4848
related:
4949
- "language/compact-source-files"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
id: d0e90aba-b424-4b96-b0cc-471f6141d71a
3+
slug: "url-constructors-to-uri"
4+
title: "Deprecated URL constructors to URI"
5+
category: "io"
6+
difficulty: "intermediate"
7+
jdkVersion: "20"
8+
oldLabel: "Deprecated URL constructor"
9+
modernLabel: "Java 20+"
10+
oldApproach: "Direct URL construction"
11+
modernApproach: "URI then URL"
12+
oldCode: |-
13+
URL endpoint =
14+
new URL("https://example.com/api?q=java");
15+
modernCode: |-
16+
URI endpointUri =
17+
URI.create("https://example.com/api?q=java");
18+
URL endpoint = endpointUri.toURL();
19+
summary: "Parse and compose resource identifiers as URI values before converting to URL\
20+
\ when necessary."
21+
explanation: "URL constructors were deprecated in JDK 20 because URL parsing and equality\
22+
\ have surprising protocol-handler behavior. URI is the preferred immutable representation\
23+
\ for parsing, composition, comparison, and normalization; convert only at APIs that\
24+
\ require URL."
25+
whyModernWins:
26+
- icon: "✅"
27+
title: "Avoids deprecation"
28+
desc: "Removes use of deprecated URL constructors."
29+
- icon: "🧠"
30+
title: "Predictable semantics"
31+
desc: "URI comparison does not perform network-dependent resolution."
32+
- icon: "🧩"
33+
title: "Better composition"
34+
desc: "URI is designed for parsing and manipulating identifiers."
35+
support:
36+
state: "available"
37+
description: "URL constructors deprecated since JDK 20 (March 2023)"
38+
prev: "io/http-websocket-client"
39+
next: "io/io-class-console-io"
40+
related:
41+
- "io/http-client"
42+
- "io/path-of"
43+
- "io/reading-files"
44+
tags:
45+
- io
46+
- http
47+
- migration
48+
docs:
49+
- title: "URI"
50+
href: "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URI.html"
51+
- title: "URL"
52+
href: "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URL.html"

‎content/security/pem-encoding.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ whyModernWins:
3939
support:
4040
state: "preview"
4141
description: "Preview in JDK 25 (JEP 470). Requires --enable-preview."
42-
prev: "datetime/hex-format"
42+
prev: "datetime/locale-of"
4343
next: "security/key-derivation-functions"
4444
related:
4545
- "security/key-derivation-functions"

0 commit comments

Comments
 (0)