External Interfaces/API    

Obtaining Information About Methods

MATLAB offers several functions to help obtain information related to the Java methods you are working with. You can request a list of all of the methods that are implemented by any class. The list may be accompanied by other method information such as argument types and exceptions. You can also request a listing of every Java class that you loaded into MATLAB that implements a specified method.

Methodsview: Displaying a Listing of Java Methods

If you want to know what methods are implemented by a particular Java (or MATLAB) class, use the methodsview function in MATLAB. Specify the class name (along with its package name, for Java classes) in the command line. If you have imported the package that defines this class, then the class name alone will suffice.

The following command lists information on all methods in the java.awt.MenuItem class.

A new window appears, listing one row of information for each method in the class. This is what the methodsview display looks like. The fieldnames shown at the top of the window are described following the figure.

Each row in the window displays up to six fields of information describing the method. The table below lists the fields displayed in the methodsview window along with a description and examples of each field type.

Table 5-1: Fields Displayed in the Methodsview Window
Field Name
Description
Examples
Qualifiers
Method type qualifiers
abstract, synchronized
Return Type
Data type returned by the method
void, java.lang.String
Name
Method name
addActionListener, dispatchEvent
Arguments
Arguments passed to method
boolean, java.lang.Object
Other
Other relevant information
throws java.io.IOException
Parent
Parent of the specified class
java.awt.MenuComponent

Using the Methods Function on Java Classes

In addition to methodsview, the MATLAB methods function, that returns information on methods of MATLAB classes, will also work on Java classes. You can use any of the following forms of this command.

Use methods without the '-full' qualifier to return the names of all the methods (including inherited methods) of the class. Names of overloaded methods are listed only once.

With the '-full' qualifier, methods returns a listing of the method names (including inherited methods) along with attributes, argument lists, and inheritance information on each. Each overloaded method is listed separately.

For example, display a full description of all methods of the java.awt.Dimension object.

Determining What Classes Define a Method

You can use the which function to display the fully qualified name (package and class name) of a method implemented by a loaded Java class. With the -all qualifier, the which function finds all classes with a method of the name specified.

Suppose, for example, that you want to find the package and class name for the concat method, with the String class currently loaded. Use the command

If the java.lang.String class has not been loaded, the same which command would give the output

If you use which -all for the method equals, with the String and java.awt.Frame classes loaded, you see the following display.

The which function operates differently on Java classes than it does on MATLAB classes. MATLAB classes are always displayed by which, whether or not they are loaded. This is not true for Java classes. You can find out which Java classes are currently loaded by using the command [m,x,j]=inmem, described in Determining Which Classes Are Loaded.

For a description of how Java classes are loaded, see Making Java Classes Available to MATLAB.


  Invoking Static Methods on Java Classes Java Methods That Affect MATLAB Commands