JDK provider and version disparities

I am using Matlab Compiler SDK to make `intlinprog` invokable from Java. I don't program in Java (yet), but have used C++/STL 15 years ago, and used OOP in VBA and Matlab. Java coding logic will probably not be a showstopper for a newbie like me; design patterns, may be more of a challenge, but my stumbling block right now is Java/JDK versions. I've read all I can about them, and now have to discover the reality by doing.
Disparity in JDK provider
I ran into my first version puzzlement in Matlab documentation on configuring the java environment:
[1] https://www.mathworks.com/help/compiler_sdk/ml_code/configure-your-java-environment.html
It says to find Java version in my MATLAB installation using `version -java`. In my MATLAB, the provider is Oracle:
Java 1.8.0_181-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
However, the documentation [1] says to get the JDK from AdoptOpenJDK. I'm wondering whether this is a mistake? I have in fact installed AdoptOpenJDK's jdk-11.0.8.10-openj9, but I haven't found an Oracle JDK at their website.
Disparity in Java versions
Since Matlab has its own requirements for JDK version, is there a problem if the system that will invoke the Java-wrapped `intlinprog` uses a different JDK? I've read that Java is largely backward compatible, but I don't know what that means in this context.
Thanks for any clarification on the above disparities, and any reconciliation needed. Meanwhile, I will forge ahead with the documentation without changing my JDK unless I run into problems.

 Accepted Answer

Todd Flanagan
Todd Flanagan on 29 Oct 2020
Edited: Todd Flanagan on 29 Oct 2020
You are correct that MATLAB ships with an Oracle version of the JRE. Compiler SDK for Java requires a JDK to compile Java code. MATLAB currently supoprts Java 8, so you are free to use whichever 1.8 compliant JDK you prefer.
The current supported JDK Versiion as well as compilers for other languages are listed here.

5 Comments

FM
FM on 29 Oct 2020
Edited: FM on 29 Oct 2020
Thanks, Todd.
I was wondering if you might be able to clarify by responding to the following question.
  1. Is the only requirement for 1.8 compliance that JDK have "the same major version" as the output of "version -java" [1]? Would that be version 8 (which is the same as 1.8, from my internet search)?
  2. It doesn't matter that "version -java" returns an ORACLE provider while the reference [1] says to go to AdoptOpenJDK?
  3. As well, my Java wrapped "intlinprog" will be invoked from another application, into which I have no visibility. Is it similarly constrained to use version 8 / 1.8?
Thanks.
NOTES:
[1] https://www.mathworks.com/help/compiler_sdk/ml_code/configure-your-java-environment.html
Yes, Java 8 refers to JDK 1.8.x. It doesn't matter that MATLAB is using an Oracle, JRE. You can use either JDK. It's up to you. We see a lot of customers using OpenJDK, so we note it's support.
In general, you can use a jar generated in Java 8 with later versions of Java and that should be true of jars built with Compiler SDK.
Thanks again, Todd. I will experiment a bit with sample java invoker code so that I can report to the developers of the host system what was shown to work.
This sounds different to mine.
I jsut installed Matlab2021a.
When i run version-java, it is a oracle java1.8,
but when i run compiler SDK, it is using java11.
This cause the produced by compiler SDK java code is uncompatible to run.
Also, my shell is using java1.8 as well
FM
FM on 5 May 2021
Edited: FM on 5 May 2021
I revisited my work using Compiler SDK to understand your comment. I was reminded of how confusing I found Java versioning to be, but that's more a consequence of its success and wide-spread usage. This article helped (I found).
I then fired up Compiler SDK to see what JDK it uses, but wasn't able to find my way to that information. Can you please describe what you did to determine that Compiler SDK uses Java 11? I open Compiler SDK from the Matlab GUI using Apps -> Library Compiler. I am using Matlab 2019a.
Thanks.

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

FM
on 25 Sep 2020

Edited:

FM
on 5 May 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!