Java-based functions should work with any Java version compatible with the Matlab release. Matlab in general does not bundle Java from the factory installation, but Java may have been installed by a system administrator. One cannot assume that Java will or will not be present on a given Matlab installation.
Matlab's Java language interface was introduced in Matlab 6.0 R12 in the year 2000. Our optional Java backend functions use only factory Java class--no third-party Java libraries are used.
Tell Java Virtual Machine (JVM) version:
version("-java")Get the Java API level:
stdlib.java_api()Get the Java vendor:
stdlib.java_vendor()Get the Java version:
stdlib.java_version()Tell JVM details:
je = jenv
% Tell the JAVA_HOME directory
disp(je.Home)As general information (not used by Matlab-stdlib), non-factory Java classes can be used in Matlab.
The Matlab Java interface is like other Matlab external languages such as Python. Matlab JVM can be configured to a compatible Java library by using the jenv Matlab function.
For example, to use the JDK 17 on macOS download and extract the ARM64 Compressed Archive. Tell Matlab to use this JDK from the Matlab console by:
jenv("/path/to/jdk-17/Contents/Home")Or for the Amazon Corretto JDK 11 on macOS:
jenv("/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home/")On Windows, obtain OpenJDK with WinGet, which installs under "$Env:ProgramFiles/Microsoft/jdk-*":
winget install Microsoft.OpenJDK.21To revert back to the default JRE if Matlab can't start or has problems, from system Terminal (not within Matlab):
matlab_jenv factory