User`s manual
5 Calling Java from MATLAB
5-10
Creating and Using Java Objects
In MATLAB, you create a Java object by calling one of the constructors of that
class. You then use commands and programming statements to perform
operations on these objects. You can also save your Java objects to a MAT-file
and, in subsequent sessions, reload them into MATLAB.
This section addresses the following topics:
•“Constructing Java Objects”
•“Concatenating Java Objects”
•“Saving and Loading Java Objects to MAT-Files”
•“Finding the Public Data Fields of an Object”
•“Accessing Private and Public Data”
•“Determining the Class of an Object”
Constructing Java Objects
You construct Java objects in MATLAB by calling the Java class constructor,
which has the same name as the class. For example, the following constructor
creates a
Frame object with the title 'Frame A' and the other properties with
their default values.
frame = java.awt.Frame('Frame A');
Displaying the new object frame shows the following.
frame =
java.awt.Frame[frame0,0,0,0x0,invalid,hidden,layout=
java.awt.BorderLayout,resizable,title=Frame A]
All of the programming examples in this chapter contain Java object
constructors. For example, the sample code for Reading a URL creates a
java.net.URL object with the constructor
url = java.net.URL(...
'http://www.ncsa.uiuc.edu/demoweb/url-primer.html')
Using the javaObject Function
Under certain circumstances, you may need to use the javaObject function to
construct a Java object. The following syntax invokes the Java constructor for