Using Java from MATLAB: An Overview

www.kxcad.net Home > CAE Software Index > MATLAB Index >


Your Ad Here

Java Interface Is Integral to MATLAB

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.

Benefits of the MATLAB Java Interface

The MATLAB Java interface enables you to:

Who Should Use the MATLAB Java Interface

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:

To Learn More About Java Programming

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:

Another place to find information is the JavaSoft Web site.

http://www.javasoft.com

For other suggestions on object-oriented programming resources, see:

Platform Support for the Java Virtual Machine

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

Using a Different Version of the Java JVM

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.

To change the JVM version that MATLAB uses, follow these steps:

  1. Download the JVM Version You Want to Use.

  2. Locate the Root of the Run-time Path for this Version.

  3. Set the MATLAB_JAVA Environment Variable to this Path.

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.

Download the JVM Version You Want to Use

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.

Locate the Root of the Run-time Path for this Version

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.

Set the MATLAB_JAVA Environment Variable to this Path

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:

  1. Click Settings in the Start Menu.

  2. Choose Control Panel.

  3. Click System.

  4. Choose the Advanced tab and then click the Environment Variables button.

  5. 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>
  


© 1984-2007 The MathWorks, Inc. Terms of Use Patents Trademarks Acknowledgments

Your Ad Here