|
| 1 | +# Matlab-Stdlib Java implementation |
| 2 | + |
| 3 | +Matlab has used Java extensively internally for over a decade. |
| 4 | +While the "New Desktop" is HTML and JavaScript based, and already other new GUI elements in Matlab were not using Java, the underlying JRE interface is treated at least like other Matlab external languages such as C++ and Python. |
| 5 | +Matlab-Stdlib uses only factory JRE classes. |
| 6 | + |
| 7 | +For reference, it is readily possible in general to use non-factory |
| 8 | +[Java classes](https://www.mathworks.com/help/matlab/matlab_external/static-path-of-java-class-path.html) |
| 9 | +in Matlab. |
| 10 | + |
| 11 | +The Matlab-Stdlib package uses Java functions throughout, including: |
| 12 | + |
| 13 | +* [java.lang.ProcessBuilder](https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/ProcessBuilder.html) |
| 14 | +* [java.lang.System](https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/System.html) |
| 15 | +* [java.nio.file](https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/Files.html) |
| 16 | +* [java.io.File](https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/io/File.html) |
| 17 | +* [java.net.InetAddress](https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/net/InetAddress.html) |
| 18 | +* [java.lang.management.ManagementFactory](https://docs.oracle.com/en/java/javase/21/docs/api/jdk.management/com/sun/management/OperatingSystemMXBean.html) |
| 19 | +* [java.security.MessageDigest](https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/security/MessageDigest.html) |
| 20 | + |
| 21 | +## Java version |
| 22 | + |
| 23 | +Get the JVM version with |
| 24 | + |
| 25 | +```matlab |
| 26 | +version("-java") |
| 27 | +``` |
| 28 | + |
| 29 | +The Matlab default |
| 30 | +[JVM can be configured](https://www.mathworks.com/help/matlab/matlab_external/configure-your-system-to-use-java.html) |
| 31 | +to |
| 32 | +[compatible JRE](https://www.mathworks.com/support/requirements/language-interfaces.html) |
| 33 | +across |
| 34 | +[Matlab versions](https://www.mathworks.com/support/requirements/openjdk.html) |
| 35 | +by using the |
| 36 | +[jenv](https://www.mathworks.com/help/matlab/ref/jenv.html) |
| 37 | +Matlab function. |
| 38 | + |
| 39 | +For example, to use the |
| 40 | +[JDK 17 on macOS](https://www.oracle.com/java/technologies/downloads/#jdk17-mac) |
| 41 | +download and extract the ARM64 Compressed Archive. |
| 42 | +Tell Matlab to use this JDK from the Matlab console by: |
| 43 | + |
| 44 | +```matlab |
| 45 | +jenv("/path/to/jdk-17/Contents/Home") |
| 46 | +``` |
| 47 | + |
| 48 | +To |
| 49 | +[revert back to the factory JRE](https://www.mathworks.com/help/matlab/ref/matlab_jenv.html) |
| 50 | +if Matlab can't start or has problems, from system Terminal do: |
| 51 | + |
| 52 | +```sh |
| 53 | +matlab_jenv factory |
| 54 | +``` |
0 commit comments