SlideShare ist ein Scribd-Unternehmen logo
1 von 6
Downloaden Sie, um offline zu lesen
JDK 20: The new features in Java 20
For more than 25 years, Java has empowered developers to design and build the next
generation of robust, scalable, and secure applications,” said Georges Saab, senior vice
president of development, Java Platform and chair, OpenJDK Governing Board, Oracle.
“The innovative new enhancements in Java 20 reflect the vision and invaluable efforts
the global Java community has contributed throughout Java’s existence. With the
support provided by Oracle’s ongoing Java technology leadership and community
stewardship, Java has never been more relevant as a contemporary language and
platform that helps developers improve productivity.”
Oracle on March 21, 2023, announced the availability of Java 20, the latest version of
the world’s number one programming language and development platform. Java 20
(Oracle JDK 20) delivers thousands of performance, stability, and security
improvements, including platform enhancements that will help developers improve
productivity and drive innovation and growth across their organizations
New Features
These are the features that made into Java 20 release are incubator or preview
features. These are features that still need to be completed and must be explicitly
activated (with –enable-preview in the java and javac commands) in order to be able to
test them.
Vector API (Fifth Incubator) – JEP 438
The Vector API was first proposed by JEP 338 in JDK 16, and then it was re-incubated in
JDK17, JDK18, JDK19 and JDK20.
To explain how the Java Vector API abstraction works, we need to explore different CPU
architectures and provide a basic understanding of data-parallel computation. In
contrast to a regular computing operation, as in 1+1, where two “pieces of data” are
added in one operation, a data-parallel operation is executing a simple operation (e.g.,
+) on multiple “pieces of data” at the same time. This mode of operation is called SIMD
(Single Instruction, Multiple Data), whereas the traditional way of execution is called
SISD (Single Instruction, Single Data). The performance speed-up results from applying
the same operation on more than one “piece of data” within one CPU cycle. As a simple
example: Instead of adding each element of an array A with each element of an array B,
we take chunks of array A and array B and operate simultaneously. The two modes are
illustrated below and should provide evidence of why SIMD should increase
computational performance.
Here is simple example, we want to find hypotenuse value of a triangle:
The same code converted into Vector API looks like this:
To explain this, we are dividing array into small parts and finding the hypotenuse of all
values together. AVX compatible CPUs can handle 256 Bits while AVX-512 can provide
512 bits of data-width. One operation usually takes 32 Bits of data-width, so if we take
256 Bits of CPU and 32 Bits of data, we can perform same operation on 256/32=8 values
of an array. But it changes CPU by CPU, here “FloatVector.SPECIES_PREFERRED” provides
that value. Then we are dividing array into 8 parts, until we can. But last part of an array
can be between 1-7 too, which cannot be grouped to 8, so we have to perform that part
manually. There is another option mask, which checks that array size can be grouped or
not and we can pass that mask value in “FloatVector.fromArray” and
“FloatVector.IntoArray” method like below code, but it is less performant:
This feature is yet not added in latest IDEs, so you have to add vector APIs’ module using
below command:
–add-modules=jdk.incubator.vector
Scoped Values (Incubator) – JEP 429
Scoped values allow a value (i.e., any object) to be stored for a limited time in such a
way that only the thread that wrote the value can read it. If multiple threads use the
same ScopedValue field, it may contain a different value from the point of view of each
thread.
If you are familiar with ThreadLocal variables, this will sound familiar. In fact, scoped
values are a modern alternative for thread locals. In ThreadLocal, it stores value in a
map, with Thread being the key and value being the values, so values are stored until
that thread dies or we remove it from map using .remove() method, otherwise the value
will be stored in map forever, which can cause memory leak and new threads are being
created with the current thread so all values from current thread will be duplicated,
hence it can create memory footprint. ScopedValues solve this problem.
In ScopedValues, we can pass that object value in “ScopedValue.where(
)” and then we
can pass runnable method in “.run()” like below:
Scoped values are usually created as public static fields like above example, so they
can be retrieved from any method without us having to pass them as parameters to
those methods.
MatchException for Exhausting Switch
An exhaustive switch (i.e., a switch that includes all possible values) throws a
MatchException (rather than an IncompatibleClassChangeError) if it is determined at
runtime that no switch label matches.
That can happen if we subsequently extend the code but only recompile the changed
classes. The best way to show this is with an example:
Using the Position record from the “Record Patterns” chapter, we define a sealed
interface Shape with the implementations Rectangle and Circle:
In addition, we write a ShapeDebugger that prints different debug information depending
on the Shape implementation:
Summary:
Hence, to conclude Java20 offers mainly with “scoped values,” we get a very useful
construct in Java 20 to provide a thread and possibly a group of child threads with a
read-only, thread-specific value during their lifetime.
All other JEPs are minimally (or not at all) modified resubmissions of previous JEPs.
Java’s ability to boost performance, stability, and security continues to make it the
world’s most popular programming language.
Originally published by: JDK 20: The new features in Java 20

Weitere Àhnliche Inhalte

Was ist angesagt?

The Java Memory Model
The Java Memory ModelThe Java Memory Model
The Java Memory Model
CA Technologies
 

Was ist angesagt? (20)

The Java Memory Model
The Java Memory ModelThe Java Memory Model
The Java Memory Model
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
 
Introduction to Java 11
Introduction to Java 11 Introduction to Java 11
Introduction to Java 11
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Closures in Javascript
Closures in JavascriptClosures in Javascript
Closures in Javascript
 
Training On Angular Js
Training On Angular JsTraining On Angular Js
Training On Angular Js
 
Doctrine ORM Internals. UnitOfWork
Doctrine ORM Internals. UnitOfWorkDoctrine ORM Internals. UnitOfWork
Doctrine ORM Internals. UnitOfWork
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
React vs Angular
React vs Angular React vs Angular
React vs Angular
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
Java troubleshooting thread dump
Java troubleshooting thread dumpJava troubleshooting thread dump
Java troubleshooting thread dump
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
Java 10 New Features
Java 10 New FeaturesJava 10 New Features
Java 10 New Features
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBC
 

Ähnlich wie JDK 20: The new features in Java 20

Designing Better API
Designing Better APIDesigning Better API
Designing Better API
Kaniska Mandal
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
mwillmer
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
Ken Coenen
 

Ähnlich wie JDK 20: The new features in Java 20 (20)

Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Java 8 - Completable Future
Java 8 - Completable FutureJava 8 - Completable Future
Java 8 - Completable Future
 
Programming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectProgramming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire project
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Core java(2)
Core java(2)Core java(2)
Core java(2)
 
Designing Better API
Designing Better APIDesigning Better API
Designing Better API
 
Java 17
Java 17Java 17
Java 17
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
unit 3.docx
unit 3.docxunit 3.docx
unit 3.docx
 
Java7
Java7Java7
Java7
 
Bt0074 oops with java2
Bt0074 oops with java2Bt0074 oops with java2
Bt0074 oops with java2
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
How To Use IO Monads in Scala?
 How To Use IO Monads in Scala? How To Use IO Monads in Scala?
How To Use IO Monads in Scala?
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8
 
50 common web developer interview questions [2020 updated] [www.full stack....
50 common web developer interview questions [2020 updated]   [www.full stack....50 common web developer interview questions [2020 updated]   [www.full stack....
50 common web developer interview questions [2020 updated] [www.full stack....
 
Bytecode manipulation with Javassist for fun and profit
Bytecode manipulation with Javassist for fun and profitBytecode manipulation with Javassist for fun and profit
Bytecode manipulation with Javassist for fun and profit
 

Mehr von Inexture Solutions

Mehr von Inexture Solutions (20)

Spring Boot for WebRTC Signaling Servers: A Comprehensive Guide
Spring Boot for WebRTC Signaling Servers: A Comprehensive GuideSpring Boot for WebRTC Signaling Servers: A Comprehensive Guide
Spring Boot for WebRTC Signaling Servers: A Comprehensive Guide
 
Mobile App Development Cost 2024 Budgeting Your Dream App
Mobile App Development Cost 2024 Budgeting Your Dream AppMobile App Development Cost 2024 Budgeting Your Dream App
Mobile App Development Cost 2024 Budgeting Your Dream App
 
Data Serialization in Python JSON vs. Pickle
Data Serialization in Python JSON vs. PickleData Serialization in Python JSON vs. Pickle
Data Serialization in Python JSON vs. Pickle
 
Best EV Charging App 2024 A Tutorial on Building Your Own
Best EV Charging App 2024 A Tutorial on Building Your OwnBest EV Charging App 2024 A Tutorial on Building Your Own
Best EV Charging App 2024 A Tutorial on Building Your Own
 
What is a WebSocket? Real-Time Communication in Applications
What is a WebSocket? Real-Time Communication in ApplicationsWhat is a WebSocket? Real-Time Communication in Applications
What is a WebSocket? Real-Time Communication in Applications
 
SaaS Application Development Explained in 10 mins
SaaS Application Development Explained in 10 minsSaaS Application Development Explained in 10 mins
SaaS Application Development Explained in 10 mins
 
Best 7 SharePoint Migration Tools of 2024
Best 7 SharePoint Migration Tools of 2024Best 7 SharePoint Migration Tools of 2024
Best 7 SharePoint Migration Tools of 2024
 
Spring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdfSpring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdf
 
Best Features of Adobe Experience Manager (AEM).pdf
Best Features of Adobe Experience Manager (AEM).pdfBest Features of Adobe Experience Manager (AEM).pdf
Best Features of Adobe Experience Manager (AEM).pdf
 
React Router Dom Integration Tutorial for Developers
React Router Dom Integration Tutorial for DevelopersReact Router Dom Integration Tutorial for Developers
React Router Dom Integration Tutorial for Developers
 
Python Kafka Integration: Developers Guide
Python Kafka Integration: Developers GuidePython Kafka Integration: Developers Guide
Python Kafka Integration: Developers Guide
 
What is SaMD Model, Benefits, and Development Process.pdf
What is SaMD Model, Benefits, and Development Process.pdfWhat is SaMD Model, Benefits, and Development Process.pdf
What is SaMD Model, Benefits, and Development Process.pdf
 
Unlocking the Potential of AI in Spring.pdf
Unlocking the Potential of AI in Spring.pdfUnlocking the Potential of AI in Spring.pdf
Unlocking the Potential of AI in Spring.pdf
 
Mobile Banking App Development Cost in 2024.pdf
Mobile Banking App Development Cost in 2024.pdfMobile Banking App Development Cost in 2024.pdf
Mobile Banking App Development Cost in 2024.pdf
 
Education App Development : Cost, Features and Example
Education App Development : Cost, Features and ExampleEducation App Development : Cost, Features and Example
Education App Development : Cost, Features and Example
 
Firebase Push Notification in JavaScript Apps
Firebase Push Notification in JavaScript AppsFirebase Push Notification in JavaScript Apps
Firebase Push Notification in JavaScript Apps
 
Micronaut Framework Guide Framework Basics and Fundamentals.pdf
Micronaut Framework Guide Framework Basics and Fundamentals.pdfMicronaut Framework Guide Framework Basics and Fundamentals.pdf
Micronaut Framework Guide Framework Basics and Fundamentals.pdf
 
Steps to Install NPM and Node.js on Windows and MAC
Steps to Install NPM and Node.js on Windows and MACSteps to Install NPM and Node.js on Windows and MAC
Steps to Install NPM and Node.js on Windows and MAC
 
Python Requirements File How to Create Python requirements.txt
Python Requirements File How to Create Python requirements.txtPython Requirements File How to Create Python requirements.txt
Python Requirements File How to Create Python requirements.txt
 
Gain Proficiency in Batch Processing with Spring Batch
Gain Proficiency in Batch Processing with Spring BatchGain Proficiency in Batch Processing with Spring Batch
Gain Proficiency in Batch Processing with Spring Batch
 

KĂŒrzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

KĂŒrzlich hochgeladen (20)

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

JDK 20: The new features in Java 20

  • 1. JDK 20: The new features in Java 20 For more than 25 years, Java has empowered developers to design and build the next generation of robust, scalable, and secure applications,” said Georges Saab, senior vice president of development, Java Platform and chair, OpenJDK Governing Board, Oracle. “The innovative new enhancements in Java 20 reflect the vision and invaluable efforts the global Java community has contributed throughout Java’s existence. With the support provided by Oracle’s ongoing Java technology leadership and community stewardship, Java has never been more relevant as a contemporary language and platform that helps developers improve productivity.” Oracle on March 21, 2023, announced the availability of Java 20, the latest version of the world’s number one programming language and development platform. Java 20 (Oracle JDK 20) delivers thousands of performance, stability, and security improvements, including platform enhancements that will help developers improve productivity and drive innovation and growth across their organizations
  • 2. New Features These are the features that made into Java 20 release are incubator or preview features. These are features that still need to be completed and must be explicitly activated (with –enable-preview in the java and javac commands) in order to be able to test them. Vector API (Fifth Incubator) – JEP 438 The Vector API was first proposed by JEP 338 in JDK 16, and then it was re-incubated in JDK17, JDK18, JDK19 and JDK20. To explain how the Java Vector API abstraction works, we need to explore different CPU architectures and provide a basic understanding of data-parallel computation. In contrast to a regular computing operation, as in 1+1, where two “pieces of data” are added in one operation, a data-parallel operation is executing a simple operation (e.g., +) on multiple “pieces of data” at the same time. This mode of operation is called SIMD (Single Instruction, Multiple Data), whereas the traditional way of execution is called SISD (Single Instruction, Single Data). The performance speed-up results from applying the same operation on more than one “piece of data” within one CPU cycle. As a simple example: Instead of adding each element of an array A with each element of an array B, we take chunks of array A and array B and operate simultaneously. The two modes are illustrated below and should provide evidence of why SIMD should increase computational performance.
  • 3. Here is simple example, we want to find hypotenuse value of a triangle: The same code converted into Vector API looks like this: To explain this, we are dividing array into small parts and finding the hypotenuse of all values together. AVX compatible CPUs can handle 256 Bits while AVX-512 can provide 512 bits of data-width. One operation usually takes 32 Bits of data-width, so if we take 256 Bits of CPU and 32 Bits of data, we can perform same operation on 256/32=8 values
  • 4. of an array. But it changes CPU by CPU, here “FloatVector.SPECIES_PREFERRED” provides that value. Then we are dividing array into 8 parts, until we can. But last part of an array can be between 1-7 too, which cannot be grouped to 8, so we have to perform that part manually. There is another option mask, which checks that array size can be grouped or not and we can pass that mask value in “FloatVector.fromArray” and “FloatVector.IntoArray” method like below code, but it is less performant: This feature is yet not added in latest IDEs, so you have to add vector APIs’ module using below command: –add-modules=jdk.incubator.vector Scoped Values (Incubator) – JEP 429 Scoped values allow a value (i.e., any object) to be stored for a limited time in such a way that only the thread that wrote the value can read it. If multiple threads use the same ScopedValue field, it may contain a different value from the point of view of each thread. If you are familiar with ThreadLocal variables, this will sound familiar. In fact, scoped values are a modern alternative for thread locals. In ThreadLocal, it stores value in a map, with Thread being the key and value being the values, so values are stored until that thread dies or we remove it from map using .remove() method, otherwise the value will be stored in map forever, which can cause memory leak and new threads are being created with the current thread so all values from current thread will be duplicated, hence it can create memory footprint. ScopedValues solve this problem. In ScopedValues, we can pass that object value in “ScopedValue.where(
)” and then we can pass runnable method in “.run()” like below:
  • 5. Scoped values are usually created as public static fields like above example, so they can be retrieved from any method without us having to pass them as parameters to those methods. MatchException for Exhausting Switch An exhaustive switch (i.e., a switch that includes all possible values) throws a MatchException (rather than an IncompatibleClassChangeError) if it is determined at runtime that no switch label matches. That can happen if we subsequently extend the code but only recompile the changed classes. The best way to show this is with an example: Using the Position record from the “Record Patterns” chapter, we define a sealed interface Shape with the implementations Rectangle and Circle: In addition, we write a ShapeDebugger that prints different debug information depending on the Shape implementation:
  • 6. Summary: Hence, to conclude Java20 offers mainly with “scoped values,” we get a very useful construct in Java 20 to provide a thread and possibly a group of child threads with a read-only, thread-specific value during their lifetime. All other JEPs are minimally (or not at all) modified resubmissions of previous JEPs. Java’s ability to boost performance, stability, and security continues to make it the world’s most popular programming language. Originally published by: JDK 20: The new features in Java 20