User`s manual

5 Calling Java from MATLAB
5-12
Note Typically, you will not need to use javaObject. The default MATLAB
syntax for instantiating a Java class is somewhat simpler and is preferable for
most applications. Use
javaObject primarily for the two cases described
above.
Java Objects Are References in MATLAB
In MATLAB, Java objects are references and do not adhere to MATLAB
copy-on-assignment and pass-by-value rules. For example,
origFrame = java.awt.Frame;
setSize(origFrame, 800, 400);
newFrameRef = origFrame;
In the second statement above, the variable newFrameRef is a second reference
to
origFrame, not a copy of the object. In any code following the example above,
any change to the object at
newFrameRef also changes the object at origFrame.
This effect occurs whether the object is changed by MATLAB code, or by Java
code.
The following example shows that
origFrame and newFrameRef are both
references to the same entity. When the size of the frame is changed via one
reference (
newFrameRef), the change is reflected through the other reference
(
origFrame), as well.
setSize(newFrameRef, 1000, 800);
getSize(origFrame)
ans =
java.awt.Dimension[width=1000,height=800]
Concatenating Java Objects
You can concatenate Java objects in the same way that you concatenate native
MATLAB data types. You use either the
cat function or the square bracket
operators to tell MATLAB to assemble the enclosed objects into a single object.