Matlab / Octave detect JVM

Matlab “.m” script functionality can be readily extended with Java and Python code. It may seem obvious to check if Python is available. It is also important to check if the Matlab JVM interface is available as Matlab may be running in -nojvm mode. Starting up Matlab without the JVM disables plotting and Java functions and can be as much as 10x faster to startup Matlab:

matlab -nojvm

Detect if JVM is available from within a Matlab script by:

hasjvm = usejava('jvm');
% boolean

GNU Octave

Octave also has a JVM interface that extends Octave functionality. As with Matlab, the Octave JVM interface availability is checked by

hasjvm = usejava('jvm');
% boolean