top of page
Search

The Ultimate Guide to Java 21 Download and Installation

  • cherilyndicus240af
  • Aug 3, 2023
  • 13 min read


Java 21 Download: How to Install and Use the Latest Version of Java




Java is one of the most popular and widely used programming languages in the world. It is used for developing applications for desktop, web, mobile, and embedded devices. Java is also known for its platform independence, which means that you can write a program once and run it on any device that supports Java.


Java is constantly evolving and improving with new features and enhancements. The latest version of Java is Java 21, which was released in September 2023 as the next long-term support (LTS) release of Oracle's standard Java implementation. Java 21 offers many new features and improvements that make it faster, more secure, more reliable, and more expressive.




java 21 download



In this article, we will show you how to download and install Java 21 on different platforms, such as Windows, Linux, and macOS. We will also show you how to use Java 21 to run and compile programs using the java, javac, and jshell commands. By the end of this article, you will be able to use Java 21 to develop and run your own applications.


What is Java 21 and why should you download it?




Java 21 is the latest release of Java SE Platform and JDK (Java Development Kit). It is also the latest long-term support (LTS) release for the Java SE platform, which means that it will receive updates and security patches until September 2026. JDK 21 includes a complete implementation of the Java SE Platform, as well as development tools such as compilers, debuggers, profilers, and documentation.


Java 21 offers many new features and improvements that make it more powerful, productive, and enjoyable to use. Some of the highlights of Java 21 are:


Java 21 features





  • Virtual Threads: This feature allows you to create lightweight threads that can execute tasks concurrently without consuming much system resources. Virtual threads are managed by the JVM (Java Virtual Machine) and can scale up to millions of threads per process. Virtual threads can improve the performance and scalability of applications that perform a lot of blocking operations, such as I/O or network calls.



  • Record Patterns: This feature allows you to use records as patterns in switch expressions and statements. Records are a special kind of class that provide a compact way to declare data-only classes with predefined methods such as equals, hashCode, toString, etc. Record patterns allow you to deconstruct records into their components and match them against values in a switch expression or statement.



  • Pattern Matching for switch: This feature allows you to use patterns in switch expressions and statements. Patterns are a way to test whether a value has a certain shape or structure, such as being an instance of a class, having a certain type, or having certain properties. Pattern matching for switch allows you to write concise and expressive code that can handle multiple cases with a single switch expression or statement.



  • Vector API: This feature provides an API (Application Programming Interface) for performing vector computations. Vector computations are operations that apply the same function to multiple elements of an array or a vector simultaneously. Vector computations can improve the performance of applications that perform intensive mathematical calculations, such as machine learning, image processing, cryptography, etc.



  • Sequenced Collections: This feature Sequenced Collections: This feature introduces a new interface called Sequenced that extends the Collection interface. Sequenced collections are collections that maintain a stable order of their elements, regardless of the implementation. Sequenced collections can improve the consistency and predictability of applications that rely on the order of elements in a collection.



  • Text Blocks: This feature allows you to write multi-line strings without using escape sequences or concatenation operators. Text blocks are delimited by three double quotes (""") and can contain any characters, including newlines, tabs, spaces, etc. Text blocks can improve the readability and maintainability of applications that deal with large or complex strings, such as SQL queries, HTML templates, JSON data, etc.



Java 21 compatibility




Java 21 is backward compatible with previous versions of Java, which means that you can run existing Java applications on Java 21 without any changes. However, some features of Java 21 may require you to update your source code or use new compiler options to enable them. For example, to use virtual threads, you need to use the --enable-preview option and set the source and target versions to 21. To use record patterns, you need to use the --enable-preview option and set the source version to 21.


Java 21 is also forward compatible with future versions of Java, which means that you can write Java applications using Java 21 features and run them on future versions of Java without any changes. However, some features of Java 21 may be experimental or subject to change in future versions of Java. For example, virtual threads and record patterns are preview features in Java 21, which means that they are not final and may change or be removed in future versions of Java.


Java 21 performance




Java 21 offers many performance improvements over previous versions of Java, which can make your applications run faster and more efficiently. Some of the performance improvements in Java 21 are:



  • Faster startup time: Java 21 reduces the startup time of Java applications by using class data sharing (CDS) and application class-data sharing (AppCDS). CDS allows the JVM to share common class metadata across multiple JVM processes, reducing the memory footprint and improving the startup performance. AppCDS allows the JVM to share application-specific class data across multiple JVM processes, reducing the loading time and improving the startup performance.



  • Faster garbage collection: Java 21 improves the garbage collection (GC) performance by using ZGC (Z Garbage Collector) and Shenandoah GC as default GC algorithms for low-latency applications. ZGC and Shenandoah GC are concurrent GC algorithms that can handle large heaps (up to 16 terabytes) with low pause times (less than 10 milliseconds). ZGC and Shenandoah GC can improve the responsiveness and throughput of applications that require low latency and high scalability.



  • Faster vector computations: Java 21 improves the vector computation performance by using the Vector API and hardware acceleration. The Vector API provides an API for performing vector computations using SIMD (Single Instruction Multiple Data) instructions. SIMD instructions allow the CPU to perform the same operation on multiple data elements at once, improving the performance of vector computations. Hardware acceleration allows the JVM to use platform-specific hardware features, such as AVX-512 on Intel processors or SVE on ARM processors, to speed up vector computations.



How to download and install Java 21 on different platforms




To use Java 21, you need to download and install JDK 21 on your platform. JDK 21 includes JRE (Java Runtime Environment), which contains the JVM and the libraries needed to run Java applications, and JDK (Java Development Kit), which contains the tools needed to develop Java applications.


java 21 download oracle


java 21 download openjdk


java 21 download windows 10


java 21 download linux


java 21 download mac


java 21 download zip


java 21 download exe


java 21 download msi


java 21 download rpm


java 21 download deb


java 21 download tar.gz


java 21 download dmg


java 21 download jdk


java 21 download jre


java 21 download graalvm


java 21 download zgc


java 21 download shenandoah


java 21 download features


java 21 download release notes


java 21 download documentation


java 21 download api javadoc


java 21 download early access builds


java 21 download preview features


java 21 download experimental features


java 21 download incubator features


java 21 download string templates


java 21 download sequenced collections


java 21 download record patterns


java 21 download pattern matching for switch


java 21 download foreign function and memory api


java 21 download unnamed patterns and variables


java 21 download virtual threads


java 21 download unnamed classes and instance main methods


java 21 download scoped values


java 21 download vector api


java 21 download key encapsulation mechanism api


java 21 download structured concurrency


java 21 download free to use in production and free to redistribute under the oracle no fee terms and conditions


java 21 download reference implementation of version 21 of the Java SE Platform as specified by JSR396 in the Java Community Process


java 21 download rampdown phase one


You can download JDK 21 from Oracle's website: . You can choose between different editions of JDK 21, such as Oracle JDK, OpenJDK, or GraalVM. You can also choose between different platforms, such as Windows, Linux, macOS, Solaris, etc.


After downloading JDK 21, you need to install it on your platform. The installation process may vary depending on your platform and edition of JDK 21. Here are some general steps for installing JDK 21 on different platforms:


Downloading Java 21 from Oracle




To download JDK 21 from Oracle's website, you need to follow these steps:



  • Go to .



  • Select your platform from the list of available platforms.Click on the Download button next to the edition of JDK 21 that you want to download, such as Oracle JDK, OpenJDK, or GraalVM.



  • Accept the license agreement and choose the file that matches your platform and architecture, such as Windows x64 Installer, Linux x64 Compressed Archive, macOS x64 Installer, etc.



  • Save the file to your preferred location on your computer.



Installing Java 21 on Windows




To install JDK 21 on Windows, you need to follow these steps:



  • Double-click on the downloaded file, such as jdk-21_windows-x64_bin.exe.



  • Follow the instructions on the installer wizard to complete the installation. You can choose the default options or customize them according to your preferences.



  • The installer will create a folder named jdk-21 in the location that you specified, such as C:\Program Files\Java\jdk-21. This folder contains the JRE and the JDK for Java 21.



Configuring JAVA_HOME and PATH variables




To use Java 21 from the command line or from other applications, you need to configure two environment variables: JAVA_HOME and PATH. JAVA_HOME is a variable that points to the location of your JDK installation, and PATH is a variable that contains a list of directories where the system looks for executable files.


To configure JAVA_HOME and PATH variables on Windows, you need to follow these steps:



  • Open the Control Panel and click on System and Security.



  • Click on System and then click on Advanced system settings.



  • Click on Environment Variables.



  • Under System variables, click on New.



  • Type JAVA_HOME as the variable name and type the path to your JDK installation as the variable value, such as C:\Program Files\Java\jdk-21. Click OK.



  • Under System variables, select Path and click on Edit.



  • Click on New and type %JAVA_HOME%\bin. Click OK.



  • Click OK to close all the windows.



Verifying the installation




To verify that you have successfully installed and configured Java 21 on Windows, you need to follow these steps:



  • Open a command prompt by typing cmd in the search box and pressing Enter.



  • Type java -version and press Enter. You should see something like this:



C:\Users\user>java -version java version "21" 2023-09-14 LTS Java(TM) SE Runtime Environment (build 21+12-LTS-237) Java HotSpot(TM) 64-Bit Server VM (build 21+12-LTS-237, mixed mode, sharing)


If you see a message like this, it means that you have successfully installed and configured Java 21 on Windows.


Installing Java 21 on Linux




To install JDK 21 on Linux, you need to follow these steps:



  • Open a terminal window by pressing Ctrl+Alt+T or by clicking on the terminal icon.



  • Navigate to the directory where you downloaded the file, such as jdk-21_linux-x64_bin.tar.gz.



  • Extract the file by typing tar -xvf jdk-21_linux-x64_bin.tar.gz and pressing Enter. This will create a folder named jdk-21 in the current directory. This folder contains the JRE and the JDK for Java 21.



  • Move the folder to a permanent location, such as /usr/local/java, by typing sudo mv jdk-21 /usr/local/java and pressing Enter. You may need to enter your password to execute this command.



Configuring JAVA_HOME and PATH variables




To use Java 21 from the command line or from other applications, you need to configure two environment variables: JAVA_HOME and PATH. JAVA_HOME is a variable that points to the location of your JDK installation, and PATH is a variable that contains a list of directories where the system looks for executable files.


To configure JAVA_HOME and PATH variables on Linux, you need to follow these steps:



  • Open a text editor by typing gedit or nano in the terminal window and pressing Enter.



  • Open the file .bashrc in your home directory by typing gedit /.bashrc or nano /.bashrc and pressing Enter. This file contains commands that are executed when you open a new terminal window.



Add these lines at the end of the file:export JAVA_HOME=/usr/local/java/jdk-21 export PATH=$PATH:$JAVA_HOME/bin


  • Save and close the file by pressing Ctrl+S and Ctrl+Q or Ctrl+X and Y.



  • Reload the file by typing source /.bashrc and pressing Enter. This will apply the changes to the current terminal window.



Verifying the installation




To verify that you have successfully installed and configured Java 21 on Linux, you need to follow these steps:



  • Open a new terminal window by pressing Ctrl+Alt+T or by clicking on the terminal icon.



  • Type java -version and press Enter. You should see something like this:



user@linux:$ java -version java version "21" 2023-09-14 LTS Java(TM) SE Runtime Environment (build 21+12-LTS-237) Java HotSpot(TM) 64-Bit Server VM (build 21+12-LTS-237, mixed mode, sharing)


If you see a message like this, it means that you have successfully installed and configured Java 21 on Linux.


Installing Java 21 on macOS




To install JDK 21 on macOS, you need to follow these steps:



  • Double-click on the downloaded file, such as jdk-21_osx-x64_bin.dmg.



  • Follow the instructions on the installer wizard to complete the installation. You can choose the default options or customize them according to your preferences.



  • The installer will create a folder named jdk-21.jdk in the location /Library/Java/JavaVirtualMachines. This folder contains the JRE and the JDK for Java 21.



Configuring JAVA_HOME and PATH variables




To use Java 21 from the command line or from other applications, you need to configure two environment variables: JAVA_HOME and PATH. JAVA_HOME is a variable that points to the location of your JDK installation, and PATH is a variable that contains a list of directories where the system looks for executable files.


To configure JAVA_HOME and PATH variables on macOS, you need to follow these steps:



  • Open a terminal window by pressing Command+Space and typing terminal and pressing Enter or by clicking on the terminal icon.



  • Open the file .bash_profile in your home directory by typing nano /.bash_profile and pressing Enter. This file contains commands that are executed when you open a new terminal window.



Add these lines at the end of the file:export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home export PATH=$PATH:$JAVA_HOME/bin


  • Save and close the file by pressing Ctrl+X and Y.



  • Reload the file by typing source /.bash_profile and pressing Enter. This will apply the changes to the current terminal window.



Verifying the installation




To verify that you have successfully installed and configured Java 21 on macOS, you need to follow these steps:



  • Open a new terminal window by pressing Command+Space and typing terminal and pressing Enter or by clicking on the terminal icon.



  • Type java -version and press Enter. You should see something like this:



user@mac:$ java -version java version "21" 2023-09-14 LTS Java(TM) SE Runtime Environment (build 21+12-LTS-237) Java HotSpot(TM) 64-Bit Server VM (build 21+12-LTS-237, mixed mode, sharing)


If you see a message like this, it means that you have successfully installed and configured Java 21 on macOS.


How to use Java 21 to run and compile programs




To use Java 21 to run and compile programs, you need to use three commands: java, javac, and jshell. java is a command that launches the JVM and runs a Java application. javac is a command that compiles a Java source file into a Java class file. jshell is a command that launches an interactive shell that allows you to execute Java statements and expressions without creating a class or a method.


Here are some examples of how to use these commands:


Using the java command




To use the java command, you need to follow these steps:



  • Create a Java source file that contains your program. For example, create a file named HelloWorld.java that contains this code:



public class HelloWorld public static void main(String[] args) System.out.println("Hello, world!");



  • Compile the Java source file into a Java class file by using the javac command. For example, type javac HelloWorld.java and press Enter. This will create a file named HelloWorld.class in the same directory.



  • Run the Java class file by using the java command. For example, type java HelloWorld and press Enter. This will launch the JVM and run your program. You should see something like this:



user@platform:$ java HelloWorld Hello, world!


Using the javac command




To use the javac command, you need to follow these steps:



  • Create a Java source file that contains your program. For example, create a file named Calculator.java that contains this code:



public class Calculator public static int add(int x, int y) return x + y; public static int subtract(int x, int y) return x - y; public static int multiply(int x, int y) return x * y; public static int divide(int x, int y) return x / y;



  • Compile the Java source file into a Java class file by using the javac command. For example, type javac Calculator.java and press Enter. This will create a file named Calculator.class in the same directory.



  • You can now use the Calculator class in other Java programs or in the jshell command.



Using the jshell command




To use the jshell command, you need to follow these steps:



  • Launch the jshell command by typing jshell and pressing Enter. This will open an interactive shell that allows you to execute Java statements and expressions.



  • Type any valid Java statement or expression and press Enter. The jshell command will evaluate it and print the result or an error message. For example, type 2 + 2 and press Enter. You should see something like this:



jshell> 2 + 2 $1 ==> 4



  • You can also use variables, methods, classes, imports, etc. in the jshell command. For example, type import import Calculator and press Enter. Then type Calculator.add(10, 20) and press Enter. You should see something like this:



jshell> import Calculator imported Calculator jshell> Calculator.add(10, 20) $2 ==> 30



  • To exit the jshell command, type /exit and press Enter.



Conclusion




In this article, we have shown you how to download and install Java 21 on different platforms, such as Windows, Linux, and macOS. We have also shown you how to use Java 21 to run and compile programs using the java, javac, and jshell commands. We have also discussed some of the new features and improvements that Java 21 offers, such as virtual threads, record patterns, vector API, sequenced collections, text blocks, etc.


Java 21 is the latest and most advanced version of Java that provides many benefits for developers and users. It is faster, more secure, more reliable, and more expressive than previous versions of Java. It is also backward and forward compatible with other versions of Java, which means that you can run existing Java applications on Java 21 without any changes and write new Java applications using Java 21 features that can run on future versions of Java without any changes.


If you want to learn more about Java 21 and its features, you can visit the official website of Oracle: . You can also find tutorials, documentation, examples, and other resources on the website to help you get started with Java 21.


We hope that this article has helped you understand how to download and install Java 21 and how to use it to run and compile programs. If you have any questions or feedback, please feel free to leave a comment below. Thank you for reading!


FAQs




Here are some frequently asked questions about Java 21:



  • What is the difference between Oracle JDK and OpenJDK?



Oracle JDK and OpenJDK are two editions of JDK that provide different licensing and support options. Oracle JDK is a commercial edition of JDK that requires a subscription for production use and provides updates and security patches for at least eight years. OpenJDK is a free and open-source edition of JDK that does not require a subscription for production use and provides updates and security patches for at least six months.


  • What is GraalVM?



GraalVM is a high-performance polyglot virtual machine that supports multiple languages, such as Java, JavaScript, Python, Ruby, R, etc. GraalVM can run applications faster, use less memory, and integrate with native code. GraalVM also provides a native image feature that allows you to compile Java applications into standalone executable files that do not require a JVM to run.


  • What are preview features in Java 21?



Preview features are features that are not final and may change or be removed in future versions of Java. Preview features are intended to gather feedback from developers and users before they become permanent features. Preview features in Java 21 include virtual threads and record patterns.


  • How can I enable preview features in Java 21?



To enable preview features in Java 21, you need to use the --enable-preview option when compiling or running your program. You also need to set the source version to 21 when compiling your program. For example, to compile a program that uses record patterns, you need to type javac --enable-preview --source 21 Program.java. To run a program that uses virtual threads, you need to type java --enable-preview Program.


  • How can I update my existing Java applications to use Java 21?



To update your existing Java applications to use Java 21, you need to follow these steps:


  • Download and install JDK 21 on your platform.



  • Configure the JAVA_HOME and PATH variables to point to your JDK 21 installation.



  • Recompile your source files using the javac command with the appropriate options.



  • Run your class files using the java command with the appropriate options.



  • Test your applications for functionality and performance.



44f88ac181


 
 
 

Recent Posts

See All

Comments


bottom of page