MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

  • Java
  • OpenJDK21

Contents

  1. OpenJDK21
    1. Install from Adoptium
    2. List of JEPs
    3. Records
    4. Virtual threads
    5. Compact Source Files and Instance Main Methods

OpenJDK21

Install from Adoptium

  • https://adoptium.net/temurin/releases

  • https://github.com/adoptium/temurin21-binaries/releases/tag/jdk-21.0.7%2B6

   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

  • 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.

   1   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.

   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

  • 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.

   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 }
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01