comparison doc/interpreter/java.txi @ 18909:9887440ceb2e stable

doc: Update documentation around java_get, java_set. * NEWS: Don't include java_get, java_set in list of functions deprecated in 3.8. * java.txi: Add java_get, java_set to manual. Write documentation for using '.' operator to read/write fields of object. Add examples of using Java interface. * java_get.m, java_set.m: Change @deftypefn type to "Function File".
author Rik <rik@octave.org>
date Sun, 13 Jul 2014 17:43:19 -0700
parents dae2230227a7
children d1c649bd90e9
comparison
equal deleted inserted replaced
18908:10c38b9e5423 18909:9887440ceb2e
46 methods which return results to Octave. 46 methods which return results to Octave.
47 47
48 @cindex object, creating a Java object 48 @cindex object, creating a Java object
49 @DOCSTRING(javaObject) 49 @DOCSTRING(javaObject)
50 50
51 @cindex fields, displaying available fields of a Java object
52 @strong{FIXME:} Need documentation on how fieldnames() is overloaded to return
53 the methods of a Java object.
54
55 @cindex field, returning value of Java object field
56 @strong{FIXME:} Need documentation on how to use structure-like indexing
57 to get fields from Java object.
58
59 @cindex field, setting value of Java object field
60 @strong{FIXME:} Need documentation on how to use structure-like indexing
61 to set fields from Java object.
62
63 @DOCSTRING(isjava)
64
65 @cindex array, creating a Java array 51 @cindex array, creating a Java array
66 @DOCSTRING(javaArray) 52 @DOCSTRING(javaArray)
67 53
54 There are many different variable types in Octave but only ones created through
55 @code{javaObject} can use Java functions. Before using Java with an unknown
56 object the type can be checked with @code{isjava}.
57
58 @DOCSTRING(isjava)
59
60 Once an object has been created it is natural to find out what fields the
61 object has and to read (get) and write (set) them.
62
63 @cindex fields, displaying available fields of a Java object
64 In Octave the @code{fieldnames} function for structures has been overloaded
65 to return the fields of a Java object. For example:
66
67 @example
68 @group
69 dobj = javaObject ("java.lang.Double", pi);
70 fieldnames (dobj)
71 @result{}
72 @{
73 [1,1] = public static final double java.lang.Double.POSITIVE_INFINITY
74 [1,2] = public static final double java.lang.Double.NEGATIVE_INFINITY
75 [1,3] = public static final double java.lang.Double.NaN
76 [1,4] = public static final double java.lang.Double.MAX_VALUE
77 [1,5] = public static final double java.lang.Double.MIN_NORMAL
78 [1,6] = public static final double java.lang.Double.MIN_VALUE
79 [1,7] = public static final int java.lang.Double.MAX_EXPONENT
80 [1,8] = public static final int java.lang.Double.MIN_EXPONENT
81 [1,9] = public static final int java.lang.Double.SIZE
82 [1,10] = public static final java.lang.Class java.lang.Double.TYPE
83 @}
84 @end group
85 @end example
86
87 @cindex field, returning value of Java object field
88 The analogy of objects with structures is carried over into reading and
89 writing object fields. To read a field the object is indexed with the
90 @samp{.} operator from structures. This is the preferred method for reading
91 fields, but Octave also provides a function interface to read fields with
92 @code{java_get}. An example of both styles is shown below.
93
94 @example
95 @group
96 dobj = javaObject ("java.lang.Double", pi);
97 dobj.MAX_VALUE
98 @result{} 1.7977e+308
99 java_get ("java.lang.Float", "MAX_VALUE")
100 @result{} 3.4028e+38
101 @end group
102 @end example
103
104 @DOCSTRING(java_get)
105
106 @cindex field, setting value of Java object field
107 @DOCSTRING(java_set)
108
109 @cindex methods, displaying available methods of a Java object
110 To see what functions can be called with an object use @code{methods}.
111 For example, using the previously created @var{dobj}:
112
113 @example
114 @group
115 methods (dobj)
116 @result{}
117 Methods for class java.lang.Double:
118 boolean equals(java.lang.Object)
119 java.lang.String toString(double)
120 java.lang.String toString()
121 @dots{}
122 @end group
123 @end example
124
125 To call a method of an object the same structure indexing operator @samp{.}
126 is used. Octave also provides a functional interface to calling the methods
127 of an object through @code{javaMethod}. An example showing both styles is
128 shown below.
129
130 @example
131 @group
132 dobj = javaObject ("java.lang.Double", pi);
133 dobj.equals (3)
134 @result{} 0
135 javaMethod ("equals", dobj, pi)
136 @result{} 1
137 @end group
138 @end example
139
68 @cindex method, invoking a method of a Java object 140 @cindex method, invoking a method of a Java object
69 @DOCSTRING(javaMethod) 141 @DOCSTRING(javaMethod)
70
71 @cindex methods, displaying available methods of a Java object
72 @strong{FIXME:} Need documentation on how methods() is overloaded to return
73 the methods of a Java object.
74 142
75 The following three functions are used to display and modify the 143 The following three functions are used to display and modify the
76 class path used by the Java Virtual Machine. This is entirely separate 144 class path used by the Java Virtual Machine. This is entirely separate
77 from Octave's PATH variable and is used by the JVM to find the correct 145 from Octave's PATH variable and is used by the JVM to find the correct
78 code to execute. 146 code to execute.