Documentation Center

  • Trial Software
  • Product Updates

usejava

Determine if Java feature is available

Syntax

Description

example

tf = usejava(feature) returns logical 1 (true) if the specified feature is supported. Otherwise, it returns logical 0 (false). Use for error handling if Java® feature is unavailable.

Examples

expand all

Display Error Message

Use the following code snippet to test that the AWT GUI components are available before attempting to display a Java Frame.

if usejava('awt')
   myFrame = java.awt.Frame;
else
   disp('Unable to open a Java Frame');
end

If the AWT is not available on your system, MATLAB® displays the message.

Call error Function

Use the following code snippet to terminate a script if MATLAB does not have access to JVM™ software.

The variable, filename, is a function that contains Java code.

if ~usejava('jvm')
   error([filename ' requires Java to run.']);
end

Input Arguments

expand all

feature — Java feature'awt' | 'desktop' | 'jvm' | 'swing'

Java feature, specified as one of these values:

'awt'

Java GUI components in the Abstract Window Toolkit (AWT) components are available.

'desktop'

MATLAB interactive desktop is running.

'jvm'

Java Virtual Machine software (JVM) is running.

'swing'

Swing components (Java lightweight GUI components in the Java Foundation Classes) are available.

See Also

|

Was this topic helpful?