<> = OpenJDK21 = == Install from Adoptium == * https://adoptium.net/temurin/releases * https://github.com/adoptium/temurin21-binaries/releases/tag/jdk-21.0.7%2B6 {{{#!highlight sh cd ~ wget https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.7%2B6/OpenJDK21U-jdk_x64_linux_hotspot_21.0.7_6.tar.gz tar tvzf OpenJDK21U-jdk_x64_linux_hotspot_21.0.7_6.tar.gz tar xvzf OpenJDK21U-jdk_x64_linux_hotspot_21.0.7_6.tar.gz nano ~/.bashrc JAVA_HOME=/home/vitor/jdk-21.0.7+6/ MAVEN_HOME=/home/vitor/apache-maven-3.8.6/ PATH=$JAVA_HOME/bin/:$PATH:$MAVEN_HOME/bin/ # reload bashrc # . ~/bashrc }}} == List of JEPs == * https://openjdk.org/jeps/0 == Records == * https://openjdk.org/jeps/395 Introduced in release 16. To model data as data. Easy and concise manner to declare data-carrier classes that by default make their data immutable. Can be described as nominal tuples. {{{#!highlight java record Point(int x, int y) { } }}} == Virtual threads == * https://openjdk.org/jeps/444 Virtual threads are lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications. {{{#!highlight java try (var executor = Executors.newVirtualThreadPerTaskExecutor()) { IntStream.range(0, 10_000).forEach(i -> { executor.submit(() -> { Thread.sleep(Duration.ofSeconds(1)); return i; }); }); } // executor.close() is called implicitly, and waits //--- void handle(Request request, Response response) { var url1 = ... var url2 = ... try (var executor = Executors.newVirtualThreadPerTaskExecutor()) { var future1 = executor.submit(() -> fetchURL(url1)); var future2 = executor.submit(() -> fetchURL(url2)); response.send(future1.get() + future2.get()); } catch (ExecutionException | InterruptedException e) { response.fail(e); } } String fetchURL(URL url) throws IOException { try (var in = url.openStream()) { return new String(in.readAllBytes(), StandardCharsets.UTF_8); } } }}} == Compact Source Files and Instance Main Methods == * https://openjdk.org/jeps/512 Evolve the Java programming language so that beginners can write their first programs without needing to understand language features designed for large programs. {{{#!highlight java // java HelloWorld.java void main() { IO.println("Hello, World!"); } //---- void main() { String name = IO.readln("Please enter your name: "); IO.print("Pleased to meet you, "); IO.println(name); } //---- void main() { var authors = List.of("James", "Bill", "Guy", "Alex", "Dan", "Gavin"); for (var name : authors) { IO.println(name + ": " + name.length()); } } }}}