You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: java-21/README.md
+58-18Lines changed: 58 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -22,32 +22,32 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
22
22
23
23
## Features
24
24
25
-
* Virtual threads
25
+
***Virtual Threads**
26
26
* promotion to standard
27
27
* changed to make virtual threads always support thread-local
28
28
* in preview releases was possible to create a virtual thread without thread-local support
29
29
* flag `jdk.traceVirtualThreadLocals` to show the strack trace when a virtual threads sets a value in thread-local variable
30
-
* Scoped values
30
+
***Scoped Values**
31
31
* promoted from incubated to preview feature
32
32
* moved from pacote `jdk.incubator.concurrent` to `java.util.concurrent`
33
-
* Structured concurrency
33
+
***Structured Concurrency**
34
34
* promoted from incubated to preview feature
35
35
* moved from pacote `jdk.incubator.concurrent` to `java.util.concurrent`
36
36
* changes from JDK 19 and 20:
37
37
* changed method `StructuredTaskScope::fork` to return a `Subtask` instanceof of a `Future`
38
38
* the sealed interface `Subtask` extends `Supplier<T>`
39
39
* the method `Subtask::get` behaves exaclty like `Future::resultNow`
40
-
* calling the method `Subtask::get` never blocks, it throws an `IllegalStateException`whe calling before `join` or when the subtask has not completed successfully
41
-
* Record patterns
40
+
* calling the method `Subtask::get` never blocks, it throws an `IllegalStateException`when calling before `join` or when the subtask has not completed successfully
41
+
***Record Patterns**
42
42
* promotion to standard
43
43
* the main change is remove the support for record pattern in header of an enhanced for loop
44
-
* Pattern matching for `switch`
44
+
***Pattern Matching for `switch`**
45
45
* promotion to standard
46
46
* main changes from last JEPs:
47
47
* removed parenthesized patterns (`case int i when (i > 0)`)
48
48
* allow qualified enum constants as case constants (`case MyEnum.ITEM`)
49
49
* exhaustiveness and compatibility:
50
-
* compiler will only require exhaustiveness if the switch uses any pattern, null label or if selector expression isn't from a legacy type (char, byte, short, int, Character, Byte, Short, Integer, String or a enum)
50
+
* compiler will only require exhaustiveness if the `switch` uses any pattern, `null` label or if selector expression isn't from a legacy type (`char`, `byte`, `short`, `int`, `Character`, `Byte`, `Short`, `Integer`, `String` or a enum)
51
51
* improved switch to support pattern matching for types (like `instanceof`)
52
52
* support for `null` case
53
53
* support for guards where we can use a boolean expression (`case String s when s.length > 10`)
@@ -56,7 +56,7 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
56
56
* fall through:
57
57
*`switch` with type pattern doesn't support falling through
58
58
* if using case label with `:`, we must end the block with `break` or `yield` (`case String s: ...; break;`, `case String s: ...; yield s.length();`)
59
-
* String templates:
59
+
***String Templates**
60
60
* improve the string with embedded expressions and template processors
61
61
* goals:
62
62
* simply the creation and expression of string with computed computed
@@ -153,8 +153,7 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
153
153
StringTemplate st = StringTemplate.RAW."Test: \{null}";
154
154
var message = STR_NULL_SANITIZER.process(st);
155
155
```
156
-
157
-
* Sequenced Collections
156
+
* **Sequenced Collections**
158
157
* new interfaces to define a common way to iterate throught sequenced collections (list, sets and maps)
159
158
* [collections type hierarchy with new interfaces](https://cr.openjdk.org/~smarks/collections/SequencedCollectionDiagram20220216.png)
160
159
* sequenced collection:
@@ -190,7 +189,7 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
190
189
* `unmodifiableSequencedCollection`
191
190
* `unmodifiableSequencedSet`
192
191
* `unmodifiableSequencedMap`
193
-
* Unnamed classes and instance main methods
192
+
* **Unnamed Classes and Instance Main Methods**
194
193
* a.k.a. relaxed launch protocol
195
194
* facilitate the writing of first programm for students without needing to know another features designed for large programs
196
195
* unnamed class:
@@ -235,7 +234,7 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
235
234
* `static void main()`
236
235
* `void main(String[])`
237
236
* `void main()`
238
-
* Unnamed patterns and variables
237
+
* **Unnamed Patterns and Variables**
239
238
* goals:
240
239
* improve the readability of record patterns by ediling unnecessary nested patterns
241
240
* improve the maintanability of code by identifying variables that must be declared but will not be used
@@ -246,7 +245,7 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
246
245
* it never shadows another variable, can be used many times
247
246
* it can be used when:
248
247
* declaring a local variable (`int _ = q.remove()`)
249
-
* resource specification of a try-with-resources (`try (_ = ScopedContxt.acquire())`)
248
+
* resource specification of a try-with-resources (`try (var _ = ScopedContxt.acquire())`)
250
249
* exception parameter in a catch clause (`catch (NumberFormatException _)`)
251
250
* header of an enhanced for loop (`for (int i = 0; _ = sideEffect(); i++)`)
252
251
* header of an enhanced for loop (`for (Order _ : orders)`)
@@ -261,19 +260,60 @@ To run each example use: `java --enable-preview --source 21 <FileName.java>`
261
260
* we can use it in any type pattern
262
261
* `p instanceof Point _`
263
262
* `case Point _`
264
-
* APIs:
265
-
* improve `Thread.sleep(millis, nanos)` to actually perform sleep with sub-millisecond time
266
-
* [`java.net.http.Http Client` is now `AutoCloseable`](https://jdk.java.net/21/release-notes#JDK-8267140) and new methods were added to close/shutdown the connection pool.
267
263
264
+
### API
265
+
266
+
* changes in `Thread` class:
267
+
* improve `Thread::sleep(millis, nanos)` to actually perform sleep with sub-millisecond time
268
+
* added method `Thread::sleep(Durantion)`, `Thread::join(Durantion)` and `Thread::isVirtual`
269
+
* added methos in `Future` that doesn't declare any checked exception (but will throw a `IllegalStateException` if is not completed):
270
+
* `T resultNow()`
271
+
* `Throwable exceptionNow()`
272
+
* `State state()`: returns the current state of the task (values: `RUNNING`, `SUCCESS`, `FAILED`, `CANCELLED`)
273
+
* added method `String::indexOf(String substr, int startIndex, int endIndex)` to find substring withing a index range
274
+
* added method `StringBuilder::repeat(String str, int numberOfTimes)` to repeat a string # times
275
+
* new methods to create collection with initial capacity:
276
+
* `HashMap::newHashMap(int)`
277
+
* `HashSet::newHashSet(int)`
278
+
* `LinkedHashMap::newLinkedHashMap(int)`
279
+
* `LinkedHashSet::newLinkedHashSet(int)`
280
+
* added method `InputStream::transferTo(OutputStream)` to read the stream and send to the received output stream
281
+
* [`java.net.http.Http Client` is now `AutoCloseable`](https://jdk.java.net/21/release-notes#JDK-8267140) and new methods were added to close/shutdown the connection pool.
282
+
* classes `ExecutorService` and `ForkJoinPool` changed to implement `AutoCloseable`
283
+
* added methods to `Math` class:
284
+
* `int ceilDiv(int, int)`
285
+
* `long ceilDiv(long, int)`
286
+
* `long ceilDiv(long, long)`
287
+
* `int ceilDivExact(int, int)`
288
+
* `long ceilDivExact(long, long)`
289
+
* `int ceilMod(int, int)`
290
+
* `long ceilMod(long, int)`
291
+
* `long ceilMod(long, long)`
292
+
* division that throws `ArithmeticException` in case of overflow:
293
+
* `int divideExact(int, int)`
294
+
* `long divideExact(long, long)`
295
+
* `int floorDivExact(int, int)`
296
+
* `long floorDivExact(long, long)`
297
+
* methods to clamp a value in a range for each type `int`, `long`, `float` and `double`:
0 commit comments