taskGNU Octave - Tasks: task #12601, Octave/Matlab differences...


You are not allowed to post comments on this tracker with your current authentication level.

task #12601: Octave/Matlab differences regarding Java

Submitter:  Rik <rik5>
Submitted:  Sat 04 May 2013 10:35:40 PM UTC
Should Start On:  Sat 04 May 2013 07:00:00 AM UTC Should be Finished on:  Sat 04 May 2013 07:00:00 AM UTC
Category:  Wish Priority:  5 - Normal
Status:  None Privacy:  Public
Assigned to:  None Originator Name: 
Open/Closed:  Open Fixed Release:  None
Planned Release:  None

Mon 28 Sep 2015 11:59:36 AM UTC, comment #4: 

According to this web page:


this serialization trick will only work for Java objects that explicitly implement the Serializable interface.

I suppose many Java objects do as they usually are derived from more basic Java classes. But it could be something to watch out for.
Some more info here:

Philip Nienhuis <philipnienhuis>
Group Member
Thu 01 May 2014 10:26:14 PM UTC, comment #3: 

Another useful thing to add would be load/save support for Java objects.  This would require providing implementations for the virtual functions save_binary and load_binary in ov-java.cc.

A very reasonable approach would be to call the Serialize method of the java object itself and then just store the data.

I just tried this and it worked out fine:

x = javaObject ('java.lang.Double', pi)
fout = javaObject('java.io.FileOutputStream', '/tmp/blah.ser')
sout = javaObject ('java.io.ObjectOutputStream', fout)
sout.writeObject (x)
sout.close ()
fin = javaObject('java.io.FileInputStream', '/tmp/blah.ser')
sin = javaObject ('java.io.ObjectInputStream', fin)
xin = sin.readObject
sin.close ()
fin = javaObject('java.io.FileInputStream', '/tmp/blah.ser')
sin = javaObject ('java.io.ObjectInputStream', fin)
xin2 = javaObject ('java.lang.Double', sin.readObject())

The first time I read the object it just returned a double of 3.1416.  I think this is probably caused by Octave auto-converting the result from a Java object to a double.  The second time I called the Java constructor with the results of the readObject call and it returned a true Java object with the full value of pi.

Rik <rik5>
Group administrator
Thu 01 May 2014 09:36:12 PM UTC, comment #2: 

javachk.m has been submitted in patch #8438

Philip Nienhuis <philipnienhuis>
Group Member
Sat 19 Apr 2014 07:54:53 PM UTC, comment #1: 

As to:
/SUPPORT for method(obj) syntax.
Matlab supports either obj.method() or method(obj) without use of javaMethod call./

The obj.method() variant has worked since at least OF Java package 1.2.x, method(obj) to some extent. The OF io package is pervaded by these call types. E.g., in <io>/inst/private/__UNO_oct2spsh__.m:

    unotmp = javaObject ("com.sun.star.uno.Type", "com.sun.star.sheet.XSpreadsheet");
    sh = sheets.getByName (sh_names{1}).getObject.queryInterface (unotmp);
    unotmp = javaObject ("com.sun.star.uno.Type", "com.sun.star.container.XNamed");
    sh.queryInterface (unotmp).setName (wsh);

where only wsh, sheets and sh_names are Octave types.

Philip Nienhuis <philipnienhuis>
Group Member
Sat 04 May 2013 10:35:40 PM UTC, original submission:  

This is a list of incompatibilities between the Java implementation in Matlab and the current implementation in the development version of core Octave (not the Java package from Octave Forge).  This is a laundry list which I haven't prioritized.

im2java() function is missing

javaaddpath (-end) functionality
Requires 'clear -java' to clear out any old objects

javaclasspath (path) functionality.
path is string or cell array of strings
path is converted to absolute from relative.
Requires 'clear -java' to clear out any old objects
javaclasspath (path1, path2) functionality.

java/dlgtest.m should be removed and tests put in %!demo or %!test blocks
for each dialog class (warning, error, etc.)

Need to figure out how to call
x = java.lang.Double (4.2) directly
This would probable be a parser change and might have to wait until the classdef branch is merged to default.

box C++ routine needs to support JavaArrays such as listdlg returning []int.

Is linear indexing of Java Array allowed by Matlab?
When indexing a Java Array is a vector of the same dimension as the original matrix returned?
x = javaArray ('java.lang.Boolean', [2 3])
y = x(1)
size (y)
Should size be 1x3 as in original array, or does it not matter and 3x1 (current value) is fine.

unbox routine, does it correctly handle signed versus unsigned?

resize() method for java_object arrays needed in ov-java.cc.

disp() for primitive objects should be better.  For example, Matlab is able to display a javaArray when the type is of type java.lang.Double.

SUPPPORT for method(obj) syntax.
Matlab supports either obj.method() or method(obj) without use of javaMethod call.

clear needs a '-java' option
clear needs a '-mex' option

javachk.m needs implementation

The following routines need to be overloaded in ov-java.cc.
double (jobj) needs to be overloaded
char (job) needs to be overloaded for arrays of strings/stringbuffers.
It currently returns a cellstr which is awfully close to what is required.
struct (job) needs to be overloaded
cell (javaArray) needs to be overloaded

exist needs to be overloaded to return 8 for Java class

which expanded to cover Java methods

Rik <rik5>
Group administrator


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached


Depends on the following items: None found

   bug dependencies.


Carbon-Copy List
  • -email is unavailable- added by rik5 (Submitted the item)
  • -email is unavailable- added by rik5

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.


    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-05-16 mtmiller Dependencies- bugs #47679 is dependent
    2013-05-04 rik5 Carbon-Copy- Added jwe

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code