| External Interfaces | ![]() |
www.kxcad.net Home > CAE Software Index > MATLAB Index >
| On this page… |
|---|
Java Interface Is Integral to MATLAB Benefits of the MATLAB Java Interface Who Should Use the MATLAB Java Interface To Learn More About Java Programming |
Every installation of MATLAB includes a Java Virtual Machine (JVM), 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 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
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 MATLAB object-oriented classes, 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. For example, these recently published books may be helpful:
Java in a Nutshell (Fourth Edition), by David Flanagan
Teach Yourself Java in 21 Days, by Lemay and Perkins
Another place to find information is the JavaSoft Web site.
http://www.javasoft.com
For other suggestions on object-oriented programming resources, see:
Object-Oriented Software Construction, by Bertrand Meyer
Object-Oriented Analysis and Design with Applications, by Grady Booch, Robert A. Maksimchuk, Michael W. Engel, and Alan Brown
To find out which version of the Java Virtual Machine (JVM) is being used by MATLAB on your platform, type the following at the MATLAB prompt.
version -java
MATLAB ships with one specific version of the Java Virtual Machine (JVM) and uses this version by default with the MATLAB interface to Java. This section describes how to download and select a version other than the default.
Note MATLAB is only fully supported on the JVM that it ships with. Some components might not work properly under a different version of the JVM. For example, calling functions in a dynamically linked library that was created with a different JVM than that used by MATLAB might cause a segmentation violation error. |
To change the JVM version that MATLAB uses, follow these steps:
When you have enabled a different version of the JVM, you can verify that MATLAB is using this version by entering the version -java command documented in the previous section.
You can download the Java Virtual Machine from the Web site http://java.sun.com/j2se/downloads.html.
If you are using Linux, go to the Web site http://www.blackdown.org/java-linux/mirrors.html, and choose the version required by your processor.
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, 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 may be a subdirectory of the main JDK install directory. (If you cannot find rt.jar, look for the file classes.zip.)
For example, if the JDK is installed in D:\jdk1.2.1 on Windows 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 UNIX, if the JDE 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.
Windows 2000/XP. To set MATLAB_JAVA on Windows 2000 or Windows XP:
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.
UNIX/Linux. To set MATLAB_JAVA on UNIX or Linux systems, use the setenv command, as shown here:
setenv MATLAB_JAVA <path to JVM>
| Calling Java from MATLAB | Bringing Java Classes and Methods into MATLAB | ![]() |
© 1984-2007 The MathWorks, Inc. Terms of Use Patents Trademarks Acknowledgments