usejava

Determine whether Sun™ Java™ feature is supported in MATLAB® software

Syntax

usejava(feature)

Description

usejava(feature) returns 1 if the specified feature is supported and 0 otherwise. Possible feature arguments are shown in the following table.

Feature

Description

'awt'

Abstract Window Toolkit components1 are available

'desktop'

The MATLABinteractive desktop is running

'jvm'

The Java Virtual Machine software (JVM™) is running

'swing'

Swing components2 are available

1. Java GUI components in the Abstract Window Toolkit

2. Java lightweight GUI components in the Java Foundation Classes

Examples

The following conditional code ensures that the AWT's GUI components are available before the M-file attempts to display a Java Frame.

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

The next example is part of an M-file that includes Java code. It fails gracefully when run in a MATLAB session that does not have access to JVM software.

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

See Also

javachk

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS