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