| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
usejava(feature)
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 MATLAB interactive 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
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
![]() | urlwrite | userpath | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |