OpenJDK21

Install from Adoptium

   1 cd ~
   2 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
   3 tar tvzf OpenJDK21U-jdk_x64_linux_hotspot_21.0.7_6.tar.gz 
   4 tar xvzf OpenJDK21U-jdk_x64_linux_hotspot_21.0.7_6.tar.gz 
   5 nano ~/.bashrc
   6 JAVA_HOME=/home/vitor/jdk-21.0.7+6/
   7 MAVEN_HOME=/home/vitor/apache-maven-3.8.6/
   8 PATH=$JAVA_HOME/bin/:$PATH:$MAVEN_HOME/bin/
   9 # reload bashrc
  10 # . ~/bashrc 
  11 

List of JEPs

Records

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.

   1   record Point(int x, int y) { }

Virtual threads

Virtual threads are lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications.

   1 try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
   2     IntStream.range(0, 10_000).forEach(i -> {
   3         executor.submit(() -> {
   4             Thread.sleep(Duration.ofSeconds(1));
   5             return i;
   6         });
   7     });
   8 }  // executor.close() is called implicitly, and waits
   9 //---
  10 
  11 void handle(Request request, Response response) {
  12     var url1 = ...
  13     var url2 = ...
  14  
  15     try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
  16         var future1 = executor.submit(() -> fetchURL(url1));
  17         var future2 = executor.submit(() -> fetchURL(url2));
  18         response.send(future1.get() + future2.get());
  19     } catch (ExecutionException | InterruptedException e) {
  20         response.fail(e);
  21     }
  22 }
  23  
  24 String fetchURL(URL url) throws IOException {
  25     try (var in = url.openStream()) {
  26         return new String(in.readAllBytes(), StandardCharsets.UTF_8);
  27     }
  28 }

Compact Source Files and Instance Main Methods

Evolve the Java programming language so that beginners can write their first programs without needing to understand language features designed for large programs.

   1 // java HelloWorld.java
   2 
   3 void main() {
   4     IO.println("Hello, World!");
   5 }
   6 
   7 //----
   8 void main() {
   9     String name = IO.readln("Please enter your name: ");
  10     IO.print("Pleased to meet you, ");
  11     IO.println(name);
  12 }
  13 
  14 //----
  15 void main() {
  16     var authors = List.of("James", "Bill", "Guy", "Alex", "Dan", "Gavin");
  17     for (var name : authors) {
  18         IO.println(name + ": " + name.length());
  19     }
  20 }

Java/OpenJDK21 (last edited 2026-06-05 18:28:24 by vitor)