User`s manual
5 Calling Java from MATLAB
5-20
title = getTitle(frame)
title =
Sample Frame
All of the programming examples in this chapter contain invocations of Java
object methods. For example, the code for Reading a URL contains a call, using
MATLAB syntax, to the
openStream method on a java.net.URL object, url.
is = openStream(url)
In another example, the code for “Example – Creating and Using a Phone
Book” on page 5-73 contains a call, using Java syntax, to the
load method on a
java.utils.Properties object, pb_htable.
pb_htable.load(FIS);
Using the javaMethod Function on Nonstatic Methods
Under certain circumstances, you may need to use the javaMethod function to
call a Java method. The following syntax invokes the method,
method_name, on
Java object
J with the argument list that matches x1,...,xn. This returns the
value
X.
X = javaMethod('method_name',J,x1,...,xn);
For example, to call the startsWith method on a java.lang.String object
passing one argument, use
gAddress = java.lang.String('Four score and seven years ago');
str = java.lang.String('Four score');
javaMethod('startsWith', gAddress, str)
ans =
1
Using the javaMethod function enables you to:
•Use methods having names longer than 31 characters
•Specify the method you want to invoke at run-time, for example, as input
from an application user
The only way to invoke a method whose name is longer than 31 characters is
to use
javaMethod. The Java and MATLAB calling syntax does not accept
method names of this length.