Configure Your System to Use Java
MATLAB® provides two-way integration with the Java® programming language and supports specific OpenJDK® long-term support (LTS) releases across all platforms. You can configure your system to enable calling Java library functionality from MATLAB. To use Java in MATLAB, you must have a supported version of the Java Runtime Environment (JRE™) software installed on your system.
When you install MATLAB on Windows® or Linux® platforms, MATLAB includes Oracle® version 8 JVM®. However, for Mac computers with Apple silicon, you must download and use OpenJDK instead. For more information, see MATLAB on Apple Silicon Macs. Regardless of the operating system, you can choose to install and configure either the MATLAB Support for OpenJDK add-on or any supported OpenJDK version.
To find out what Java version MATLAB currently uses on your system, call the jenv
function.
Install and Configure OpenJDK using MATLAB Add-On
After installing MATLAB, you can install the OpenJDK add-on using the Add-Ons Explorer:
On the MATLAB Home tab, in the Environment section, click Add-Ons.
In the Add-On Explorer, search for
OpenJDK.Install the MATLAB Support for OpenJDK add-on.
In the MATLAB Command Window, clear the current JRE so that MATLAB uses the installed OpenJDK add-on.
jenv -clear
For more information, see Get and Manage Add-Ons.
Install and Configure Specific Version of OpenJDK
If you want to install a specific supported version of either OpenJDK
JDK™ or JRE, you can get the software from adoptium.net:
Download and install a supported version of OpenJDK Java from
https://adoptium.net/. For version information, see Versions of OpenJDK Compatible with MATLAB by Release.If OpenJDK is the first Java entry on your system path, then configure MATLAB with this command.
jenv("system")If OpenJDK is not the first entry and is installed in folder
JRE_path, then configure MATLAB with this command.jenv("JRE_path")Restart MATLAB.
Verify the version of Java that MATLAB is configured to use.
version -java
Alternatively, call matlab_jenv
from the operating system prompt to change the MATLAB configuration.
Use Oracle JVM Version 8
When you install MATLAB on Windows or Linux platforms, MATLAB is configured to use Oracle version 8 JVM.
See Also
Topics
- Versions of OpenJDK Compatible with MATLAB by Release
- MATLAB on Apple Silicon Macs
- MATLAB Interfaces to Other Languages