O que há de novo no Java 19?  Você deve dar o salto?

What's new in Java 19? Should you take the leap?

Java is a versatile and powerful programming language that allows developers to create robust, high-performance applications that can run on any platform. Java is the foundation for virtually all types of networked applications and is the global standard for developing and delivering mobile applications, games, web-based content, and enterprise software. With its rich set (…)

Imagem em destaque

Java is a versatile and powerful programming language that allows developers to create robust, high-performance applications that can run on any platform. Java is the foundation for virtually all types of networked applications and is the global standard for developing and delivering mobile applications, games, web-based content, and enterprise software.

With its rich set of libraries, Java allows developers to create innovative and efficient solutions. The Java platform provides an environment for developing applications with dynamic behavior. The platform also includes a set of tools that allow developers to easily design, test, optimize, and deploy their applications.

It was originally released in 1995 and has since gone through several updates. The Java programming language is a high-level object-oriented language known for its portability and platform independence.

With over 20 years under its belt, the Java programming language has become one of the most popular languages ​​in use today. In fact, according to the TIOBE Index for October 2022 Java was ranked as the third most popular programming language in the world, behind only C and Python — a trend that has continued since 2018.

New in Java 19: An Introduction

The latest update to the Java Development Kit (JDK) was released on September 20, 2021. It is a non-LTS version that aims to add several new features, including structured concurrency, logging patterns, a view of an external function, and memory API , and support for the open source Linux/RISC-V instruction set architecture (ISA).

What does non-LTS mean, you ask? Long-term support (LTS) is an extended support phase for a specific software version. Long-term support includes security updates, bug fixes, and performance improvements during the support period. Although it is often not the most up-to-date version of the software, users who require long-term support for their applications may consider using the LTS version.

For Oracle, the LTS version of Java is the industry standard until the end of its life cycle. As of 2022, the current LTS version is Java 17 and is scheduled to end its run in 2026.

In this context, non-LTS releases are small updates typically used to test new features and gather community feedback. For example, in the case of Java 19, all the features mentioned above, except the Linux/RISC-V feature, are in the preview or incubator phases.

The difference between experimental, visualization, and incubator capabilities

To understand how Java versions work, we need to familiarize ourselves with the notation used by Oracle: experimental, preview and incubator. All of these tags are used to refer to new features that have not been fully integrated into Java.

Java Previews

Visualizations were introduced in JEP12. To quote from OpenJDK : “A preview feature is a new feature of the Java language, Java Virtual Machine, or Java SE API that is fully specified, fully implemented, and yet impermanent. It is available in a JDK feature release to elicit developer feedback based on real-world usage.”

It would be fair to compare a preview with a late-stage beta test. The feature has been extensively tested and should be stable. Features that enter a preview stage are typically subject to user feedback that Oracle uses to make corrections or changes as appropriate or to eventually release them.

Preview features have a very short “grace period”, so you can expect very few changes and their full adoption is usually within a year of their initial release.

Because preview features are not permanent features on the Java SE platform, they are unavailable by default at compile time and run time. Developers who want to use visualization language APIs and features must explicitly enable them in the compiler and at runtime.

Experimental Java

Experimental features are early (mostly) versions of virtual machine-level features. Although tested, they can be risky, incomplete, or even unstable. To access experimental features, the developer typically needs to enable them using dedicated flags.

For context, if preview features are 95% complete, then experimental features are about 25% complete. They are introduced so that early adopters and enthusiasts can try out the new feature and provide feedback, report bugs, or begin exploring its potential.

Keep in mind that each vendor is free to enable/disable experimental features in their distributions as they see fit.

Java Incubator

Incubation resources are APIs distributed in the form of modules with names prefixed with “JDK.incubator.” Just like experimental features, expect incubator APIs to be buggy and unstable. The name incubator comes from the fact that you see these APIs mature over several Java releases until they are ready for the preview stage.

Java Projects

Most of the features we'll talk about today are the results of Java projects. A Project is a collaborative effort to produce a specific artifact, which may be a body of code, documentation, or some other material.

Any Collaborator may propose the creation of a new Project. If it is supported by at least one Group Leader, whose Group will Sponsor the Project, and approved by a Lazy Consensus of OpenJDK Members, then the Project will be created.

Famous projects include:

Loom Project

Project Loom is a project that promises to deliver lightweight yarn. This is done by having the Java Virtual Machine (JVM) manage scheduling instead of the operating system (OS). This way, the JVM can control the scheduling of all threads and, in theory, provide better performance.

Project Valhalla

Project Valhalla is a project to improve performance in Java. This is done by introducing value types, which are a new form of data type programmed as objects but accessed as primitives. This means they can be stored in a single array, with just a single header field for the entire array and direct access to the individual fields.

Panama Project

The Panama Project is a project that facilitates the connection of Java programs to non-Java components, such as C-based libraries. The project has several subprojects, which are being launched in incubator status in recent versions of Java. These subprojects include the Foreign-Memory Access API, the Foreign Linker API, the Vector API, and the Foreign-Function Interface API.

Amber Project

Project Amber is a project responsible for adding several new features to the Java programming language. Their mission statement is: “to explore and incubate smaller, productivity-oriented Java language features that have been accepted as candidates for PECs.”

These features include the var keyword for local variables, blocks of text, records, and pattern matching in instances of comparisons. The project is still ongoing and is currently working on adding sealed classes, pattern matching on switches, and pattern matching for registers and arrays.

New features in Java 19

Structured Concurrency

In computer science, concurrency is the ability of different parts or units of a program, algorithm, resource, or device to perform actions independently. Concurrency can improve the performance of a program or system by allowing multiple tasks to be processed simultaneously. It can also help make better use of resources such as processors, memory and disk space.

This concurrency will run multiple tasks on different threads and treat them as a single unit of work. The goals, according to OpenJDK are as follows:

  • Improve the maintainability, reliability, and observability of multithreaded code.
  • Promote a concurrent programming style that can eliminate the risks of cancellation and termination.

This is part of Project Loom, a lightweight concurrency model that allows developers to more easily write concurrent programs. It adds support for virtual threads, which are threads that are not tied to a specific CPU core. This makes it possible for a single thread to use multiple cores at the same time, which can improve performance.

Preview of registration patterns

This is a visualization feature that allows record patterns and type patterns to be nested to enable a powerful, declarative, and composable way of browsing and processing data. Based on pattern matching, for example, delivered in JDK 16 in March 2021. Plans may require logging patterns to be extended with features such as array patterns and vararg patterns. According to the JDK, the goals are to extend pattern matching to express more complex data queries without changing the syntax of type patterns.

Foreign Function View and Memory API

The External Function and Memory API is a way for Java programs to interact with code and data outside of the Java runtime. This API is efficient for invoking foreign functions and accessing external memory. It is safe to use and helps avoid the dangers and fragility of the Java Native Interface (JNI). The external function and memory API was incubated in JDK 17 and reincubated in JDK 18. The goals of this proposal include being easy to use, performing well, being general, and being secure.

Visualizing virtual threads

Virtual threads are lightweight threads that can help reduce the amount of work required to write, maintain, and observe high-throughput concurrent applications. The purposes of virtual threads include:

  • Making it easier for server applications written in the simple thread-per-request style to scale with near-optimal hardware utilization
  • Making it easier for existing code that uses the Java.lang Thread API to adopt virtual threads with minimal changes
  • Enabling troubleshooting, debugging, and profiling of virtual threads with existing JDK tools

Pattern matching view for expressions and switch statements

The third view of pattern matching for switch expressions and statements adds refinements, including replacing patterns protected by when clauses in switch blocks. Additionally, the runtime semantics of a pattern switch when the value of the selector expression is null is more in line with the semantics of the legacy switch.

The plan's goals include expanding the expressiveness and applicability of switch expressions and statements by allowing patterns to appear in case labels. Other goals include allowing developers to relax the historical null hostility of a switch when desired, increasing the security of switch statements, and ensuring that existing switch expressions and statements continue to compile without changes and execute with identical semantics.

The hope is to eventually support pattern matching throughout Java by adding it to places where expressions are used. This feature is also part of Project Amber.

Fourth incubation of a vector API

The vector API is a way for developers to write complex vector algorithms in Java. The API was previously incubated in JDK 16, JDK 17, and JDK 18. API improvements proposed for JDK 19 include improvements to loading and storing vectors to and from MemorySegments, as defined by the Foreign Function and Memory API preview. JDK 19 would also add two cross vector operations, compact and expand, along with a complementary vector mask compression operation.

The vector compression operation maps tracks from a source vector, selected by a mask, to a destination vector in track order, while the expansion operation does the reverse. The compress operation is useful in filtering query results. In another addition to the vector API, bitwise integral lanewise operations would be expanded, including operations such as counting the number of a bit, reversing bit order, and compressing and expanding bits.

The goals of the API included being clear and concise, platform independent, having reliable runtime and compilation performance on x64 and AArch64 architectures, and allowing “elegant” degradation, for situations where a vector computation cannot be fully expressed at runtime. execution as a sequence of vector operations. The vector API is from the Panamá Project.

Linux/RISC-V port

The Linux/RISC-V port would add support for a hardware instruction set that is already used by many different language toolchains. RISC-V is a family of related instruction set architectures (ISAs), and the port would only support the RV64GV configuration of RISC-V. This is a 64-bit general-purpose ISA that includes vector instructions. Java developers may consider adding support for other RISC-V configurations in the future.

Preparing for an update

Do you want to take a look at Java 19? Well, if you want to upgrade, remember these tips:

  1. Know what you need: Before upgrading, it's important to know what your business needs. Make a list of essential features and functions that will help your business run more efficiently. If nothing on our list of features seems mandatory, you might want to ask yourself if it's really necessary.
  2. Do your research: Once you know what you need, it's time to do your research and find out if Java 19 can help you. Read online reviews, talk to other companies in your industry, and get recommendations from trusted sources. Keep in mind that some of these features are still experimental, so pay close attention to potential bugs and issues.
  3. Get organized: Updating your software can be a big project, so it's important to get organized before starting anything. Create a schedule for when you want things done and make sure everyone involved knows their roles and responsibilities.
  4. Budget appropriately: One of the most important aspects of upgrading your software is budgeting correctly. Obviously, with short-term release probabilities, there is very little to consider in terms of budget. But your developers still need to read and learn the documentation so they can make the most of the update. Be ready for this incubation period.
  5. Start small and test: Do a fresh install in a sandbox and play around a bit. Take this as an opportunity to let your team know what’s new. Keep in mind that Oracle will only provide support for six months, so we should see Java 20 around March 2023

Is it time to upgrade to Java 19?

Java 19 is set to be a near-term release, with Java 20 already looming on the horizon. So should you upgrade? As always, it depends. The first question to consider is how you feel about short-term releases like this. If you don't mind updating frequently, you're better off taking advantage of the benefits that come with the latest releases.

If you prefer to stick with a single version of Java for a long period of time, you may want to wait for the next LTS release. What are the benefits of upgrading to Java 19? Firstly, it's important to note that the changes in Java 19 are not as significant as in some previous versions. Perhaps this is to be expected since it is a short-term release.

Short-term releases are generally aimed at enthusiasts, people who like to tinker with new features as quickly as possible, but they can introduce new bugs and be less stable. This is expected; After all, as we have seen, most of the new features are still in the testing phase.

For companies relying on Java 17, the answer is frankly a resounding no. While some of the new features are extremely cool, there's no reason to fix what isn't broken. You can install the JDK in a sandbox and play with the features; you can even start developing using features that have gone through multiple rounds of testing. But this is preparation for what's to come, not jumping on the bandwagon.

If you liked this, be sure to check out one of our other Java articles:

  • 6 Best Java GUI Frameworks
  • 8 Best Java IDEs and Text Editors
  • 7 Best Java Machine Learning Libraries
  • C# x Java: main differences explained
  • Golang vs Java: programming languages ​​compared and how to choose

Source: BairesDev

Conteúdo Relacionado

O Rails 8 sempre foi um divisor de águas...
Os genéricos são uma característica poderosa em Java que...
A GenAI está transformando a força de trabalho com...
Entenda o papel fundamental dos testes unitários na validação...
Aprenda como os testes de carga garantem que seu...
Aprofunde-se nas funções complementares dos testes positivos e negativos...
Vídeos deep fake ao vivo cada vez mais sofisticados...
Entenda a metodologia por trás dos testes de estresse...
Descubra a imprevisibilidade dos testes ad hoc e seu...
A nomeação de Nacho De Marco para o Fast...
Aprenda como os processos baseados em IA aprimoram o...
Java e JavaScript são duas das linguagens de programação...
Introdução Quando se trata de desenvolvimento de software, a...
Os desenvolvedores Java enfrentam uma variedade de erros relacionados...
Neste artigo, discutiremos os benefícios de gerar imagens em...
O Java 23 finalmente foi lançado, e podemos começar...
Milhares de sites são criados todos os dias. Não...
Os recursos de linguagem que serão incluídos na próxima...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.