Java Preview
Key Derivation Function API
A Key Derivation Function is a cryptographic algorithm used to generate secure keys from a password.
KDF hkdf = KDF.getInstance("HKDF-SHA256");
AlgorithmParameterSpec params =
HKDFParameterSpec.ofExtract()
.addIKM("the super secret passphrase".getBytes(StandardCharsets.UTF_8))
.addSalt("the salt".getBytes(StandardCharsets.UTF_8))
.thenExpand("my derived key description".getBytes(StandardCharsets.UTF_8), 32);
SecretKey key = hkdf.deriveKey("AES", params);
System.out.println("key = " + HexFormat.of().formatHex(key.getEncoded()));
key = f2a6084216a7f94309fdc43f07e96d4f75870ab4c3d885249bf3ba49d62e70d7
Flexible Constructor Bodies
public Person(int age) {
if (value <= 0)
throw new IllegalArgumentException("non-positive value");
super(value);
}
String Template
var name = "Duke";
var info = STR."My name is {name}";
System.out.println(info);
My name is Duke
ups
Structured Concurrency API
Random r = new Random();
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
Supplier<Integer> number1 = scope.fork(r::nextInt);
Supplier<Integer> number2 = scope.fork(r::nextInt);
try {
scope.join().throwIfFailed();
System.out.println(number1.get());
System.out.println(number2.get());
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}
}
-1656376899
1610822880
Scoped Values
Variable is valid with the value within the block and the it’s destroyed.
ScopedValue.where(NAME, "Ada").run(() ->
System.out.println(NAME.get()));
ScopedValue.where(NAME, "Aixa").run(() ->
System.out.println(NAME.get()));
private static final ScopedValue<String> NAME = ScopedValue.newInstance();
Ada
Aixa