User`s manual
5 Calling Java from MATLAB
5-14
If there is no common, lower level parent, then the resultant class is
java.lang.Object, which is the root of the entire Java class hierarchy.
byte = java.lang.Byte(127);
point = java.awt.Point(24,127);
[byte; point]
ans =
java.lang.Object[]:
[ 127]
[1x1 java.awt.Point]
Saving and Loading Java Objects to MAT-Files
Use the MATLAB save function to save a Java object to a MAT-file. Use the
load function to load it back into MATLAB from that MAT-file. To save a Java
object to a MAT-file, and to load the object from the MAT-file, make sure that
the object and its class meet all of the following criteria:
•The class implements the Serializable interface (part of the Java API), either
directly or by inheriting it from a parent class. Any embedded or otherwise
referenced objects must also implement Serializable.
•The definition of the class is not changed between saving and loading the
object. Any change to the data fields or methods of a class prevents the
loading (deserialization) of an object that was constructed with the old class
definition.
•Either the class does not have any transient data fields, or the values in
transient data fields of the object to be saved are not significant. Values in
transient data fields are never saved with the object.
If you define your own Java classes, or subclasses of existing classes, you can
follow the criteria above to enable objects of the class to be saved and loaded in
MATLAB. For details on defining classes to support serialization, consult your
Java development documentation. (See also “To Learn More About Java
Programming” on page 5-3).