| Contents | Index |
| On this page… |
|---|
Sun Java Interface Is Integral to MATLAB Software Benefits of the MATLAB Java Interface Who Should Use the MATLAB Java Interface To Learn More About Java Programming Language |
Every installation of MATLAB software includes Java Virtual Machine (JVM) software, so that you can use the Java interpreter via MATLAB commands, and you can create and run programs that create and access Java objects. For information on the MATLAB installation, see the MATLAB installation documentation for your platform.
The MATLAB Java interface enables you to:
Access Java API (application programming interface) class packages that support essential activities such as I/O and networking. For example, the URL class provides convenient access to resources on the Internet.
Access third-party Java classes
Easily construct Java objects in MATLAB workspace
Call Java object methods, using either Java or MATLAB syntax
Pass data between MATLAB variables and Java objects
The MATLAB Java interface is intended for all MATLAB users who want to take advantage of the special capabilities of the Java programming language.
For example:
You need to access, from MATLAB, the capabilities of available Java classes.
You are familiar with object-oriented programming in Java or in another language, such as C++.
You are familiar with Object-Oriented Programming, or with MATLAB MEX-files.
For a complete description of the Java language and for guidance in object-oriented software design and programming, you'll need to consult outside resources, such as http://java.sun.com/.
To find out which version of JVM software is used by MATLAB on your platform, type the following at the MATLAB prompt:
version -java
MATLAB ships with one specific version of the JVM software on all operating systems, except Apple Mac OS® X operating systems. On Mac OS X systems, MATLAB uses the JVM software provided with the operating system.
Note MATLAB is only fully supported on these versions of the JVM software. Some components might not work properly under a different version of the JVM software. For example, calling functions in a dynamically linked library that was created with a different JVM software version than that used by MATLAB might cause a segmentation violation error message. |
To change the JVM software version:
To verify that MATLAB is using the correct version of the JVM software, type the version -java command.
You can download JVM software from the Web site http://www.java.com/en/download/manual.jsp.
To get MATLAB to use the version you have just downloaded, you must first find the root of the run-time path for this JVM software version, and then set the MATLAB_JAVA environment variable to that path. To locate the JVM run-time path, find the directory in the Java installation tree that is one level up from the directory containing the file rt.jar. This might be a folder of the main Sun™ JDK™ install directory. (If you cannot find rt.jar, look for the file classes.zip.)
For example, if the JDK software is installed in D:\jdk1.2.1 on a Microsoft Windows system and the rt.jar file is in D:\jdk1.2.1\jre\lib, set MATLAB_JAVA to the directory one level up from that: D:\jdk1.2.1\jre.
On a UNIX system, if the JDE software is installed in /usr/openv/java/jre/lib and the rt.jar is in /usr/openv/java/jre/lib, set MATLAB_JAVA to the path /usr/openv/java/jre.
The way you set or modify the value of the MATLAB_JAVA variable depends on which platform you are running MATLAB on.
Choose the Advanced tab, and then click the Environment Variables button.
You now can set (or add) the MATLAB_JAVA system environment variable to the path of your JVM software.
UNIX or Linux Operating Systems.
setenv MATLAB_JAVA <path to JVM>
![]() | Using Java Libraries from MATLAB | Bringing Java Classes and Methods into MATLAB Workspace | ![]() |

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