1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Java Interface Functions (GNU Octave (version 7.3.0))</title>
<meta name="description" content="Java Interface Functions (GNU Octave (version 7.3.0))">
<meta name="keywords" content="Java Interface Functions (GNU Octave (version 7.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Java-Interface.html" rel="up" title="Java Interface">
<link href="Set-up-the-JVM.html" rel="prev" title="Set up the JVM">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<div class="subsection" id="Java-Interface-Functions">
<div class="header">
<p>
Previous: <a href="Set-up-the-JVM.html" accesskey="p" rel="prev">Set up the JVM</a>, Up: <a href="Java-Interface.html" accesskey="u" rel="up">Java Interface</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Java-Interface-Functions-1"></span><h4 class="subsection">A.4.4 Java Interface Functions</h4>
<p>The following functions are the core of the Java Interface. They provide a way
to create a Java object, get and set its data fields, and call Java methods
which return results to Octave.
</p>
<span id="index-object_002c-creating-a-Java-object"></span>
<span id="index-instance_002c-creating-a-Java-instance"></span>
<span id="XREFjavaObject"></span><dl class="def">
<dt id="index-javaObject"><span class="category">: </span><span><em><var>jobj</var> =</em> <strong>javaObject</strong> <em>(<var>classname</var>)</em><a href='#index-javaObject' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javaObject-1"><span class="category">: </span><span><em><var>jobj</var> =</em> <strong>javaObject</strong> <em>(<var>classname</var>, <var>arg1</var>, …)</em><a href='#index-javaObject-1' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Create a Java object of class <var>classsname</var>, by calling the class
constructor with the arguments <var>arg1</var>, …
</p>
<p>The first example below creates an uninitialized object, while the second
example supplies an initial argument to the constructor.
</p>
<div class="example">
<pre class="example">x = javaObject ("java.lang.StringBuffer")
x = javaObject ("java.lang.StringBuffer", "Initial string")
</pre></div>
<p><strong>See also:</strong> <a href="#XREFjavaMethod">javaMethod</a>, <a href="#XREFjavaArray">javaArray</a>.
</p></dd></dl>
<span id="index-array_002c-creating-a-Java-array"></span>
<span id="XREFjavaArray"></span><dl class="def">
<dt id="index-javaArray"><span class="category">: </span><span><em><var>jary</var> =</em> <strong>javaArray</strong> <em>(<var>classname</var>, <var>sz</var>)</em><a href='#index-javaArray' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javaArray-1"><span class="category">: </span><span><em><var>jary</var> =</em> <strong>javaArray</strong> <em>(<var>classname</var>, <var>m</var>, <var>n</var>, …)</em><a href='#index-javaArray-1' class='copiable-anchor'> ¶</a></span></dt>
<dd>
<p>Create a Java array of size <var>sz</var> with elements of class <var>classname</var>.
</p>
<p><var>classname</var> may be a Java object representing a class or a string
containing the fully qualified class name. The size of the object may
also be specified with individual integer arguments <var>m</var>, <var>n</var>, etc.
</p>
<p>The generated array is uninitialized. All elements are set to null if
<var>classname</var> is a reference type, or to a default value (usually 0) if
<var>classname</var> is a primitive type.
</p>
<p>Sample code:
</p>
<div class="example">
<pre class="example">jary = javaArray ("java.lang.String", 2, 2);
jary(1,1) = "Hello";
</pre></div>
<p><strong>See also:</strong> <a href="#XREFjavaObject">javaObject</a>.
</p></dd></dl>
<p>There are many different variable types in Octave, but only ones created
through <code>javaObject</code> can use Java functions. Before using Java with an
unknown object the type can be checked with <code>isjava</code>.
</p>
<span id="XREFisjava"></span><dl class="def">
<dt id="index-isjava"><span class="category">: </span><span><em></em> <strong>isjava</strong> <em>(<var>x</var>)</em><a href='#index-isjava' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Return true if <var>x</var> is a Java object.
</p>
<p><strong>See also:</strong> <a href="Built_002din-Data-Types.html#XREFclass">class</a>, <a href="Data-Types.html#XREFtypeinfo">typeinfo</a>, <a href="Built_002din-Data-Types.html#XREFisa">isa</a>, <a href="#XREFjavaObject">javaObject</a>.
</p></dd></dl>
<p>Once an object has been created it is natural to find out what fields the
object has, and to read (get) and write (set) them.
</p>
<span id="index-fields_002c-displaying-available-fields-of-a-Java-object"></span>
<p>In Octave the <code>fieldnames</code> function for structures has been overloaded
to return the fields of a Java object. For example:
</p>
<div class="example">
<pre class="example">dobj = javaObject ("java.lang.Double", pi);
fieldnames (dobj)
⇒
{
[1,1] = public static final double java.lang.Double.POSITIVE_INFINITY
[1,2] = public static final double java.lang.Double.NEGATIVE_INFINITY
[1,3] = public static final double java.lang.Double.NaN
[1,4] = public static final double java.lang.Double.MAX_VALUE
[1,5] = public static final double java.lang.Double.MIN_NORMAL
[1,6] = public static final double java.lang.Double.MIN_VALUE
[1,7] = public static final int java.lang.Double.MAX_EXPONENT
[1,8] = public static final int java.lang.Double.MIN_EXPONENT
[1,9] = public static final int java.lang.Double.SIZE
[1,10] = public static final java.lang.Class java.lang.Double.TYPE
}
</pre></div>
<span id="index-field_002c-returning-value-of-Java-object-field"></span>
<p>The analogy of objects with structures is carried over into reading and writing
object fields. To read a field the object is indexed with the ‘<samp>.</samp>’
operator from structures. This is the preferred method for reading fields, but
Octave also provides a function interface to read fields with <code>java_get</code>.
An example of both styles is shown below.
</p>
<div class="example">
<pre class="example">dobj = javaObject ("java.lang.Double", pi);
dobj.MAX_VALUE
⇒ 1.7977e+308
java_get ("java.lang.Float", "MAX_VALUE")
⇒ 3.4028e+38
</pre></div>
<span id="XREFjava_005fget"></span><dl class="def">
<dt id="index-java_005fget"><span class="category">: </span><span><em><var>val</var> =</em> <strong>java_get</strong> <em>(<var>obj</var>, <var>name</var>)</em><a href='#index-java_005fget' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Get the value of the field <var>name</var> of the Java object <var>obj</var>.
</p>
<p>For static fields, <var>obj</var> can be a string representing the fully
qualified name of the corresponding class.
</p>
<p>When <var>obj</var> is a regular Java object, structure-like indexing can be
used as a shortcut syntax. For instance, the following two statements are
equivalent
</p>
<div class="example">
<pre class="example"> java_get (x, "field1")
x.field1
</pre></div>
<p><strong>See also:</strong> <a href="#XREFjava_005fset">java_set</a>, <a href="#XREFjavaMethod">javaMethod</a>, <a href="#XREFjavaObject">javaObject</a>.
</p></dd></dl>
<span id="index-field_002c-setting-value-of-Java-object-field"></span>
<span id="XREFjava_005fset"></span><dl class="def">
<dt id="index-java_005fset"><span class="category">: </span><span><em><var>obj</var> =</em> <strong>java_set</strong> <em>(<var>obj</var>, <var>name</var>, <var>val</var>)</em><a href='#index-java_005fset' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Set the value of the field <var>name</var> of the Java object <var>obj</var> to
<var>val</var>.
</p>
<p>For static fields, <var>obj</var> can be a string representing the fully
qualified named of the corresponding Java class.
</p>
<p>When <var>obj</var> is a regular Java object, structure-like indexing can be
used as a shortcut syntax. For instance, the following two statements are
equivalent
</p>
<div class="example">
<pre class="example"> java_set (x, "field1", val)
x.field1 = val
</pre></div>
<p><strong>See also:</strong> <a href="#XREFjava_005fget">java_get</a>, <a href="#XREFjavaMethod">javaMethod</a>, <a href="#XREFjavaObject">javaObject</a>.
</p></dd></dl>
<span id="index-methods_002c-displaying-available-methods-of-a-Java-object"></span>
<p>To see what functions can be called with an object use <code>methods</code>. For
example, using the previously created <var>dobj</var>:
</p>
<div class="example">
<pre class="example">methods (dobj)
⇒
Methods for class java.lang.Double:
boolean equals(java.lang.Object)
java.lang.String toString(double)
java.lang.String toString()
…
</pre></div>
<p>To call a method of an object the same structure indexing operator ‘<samp>.</samp>’ is
used. Octave also provides a functional interface to calling the methods of an
object through <code>javaMethod</code>. An example showing both styles is shown
below.
</p>
<div class="example">
<pre class="example">dobj = javaObject ("java.lang.Double", pi);
dobj.equals (3)
⇒ 0
javaMethod ("equals", dobj, pi)
⇒ 1
</pre></div>
<span id="index-method_002c-invoking-a-method-of-a-Java-object"></span>
<span id="XREFjavaMethod"></span><dl class="def">
<dt id="index-javaMethod"><span class="category">: </span><span><em><var>ret</var> =</em> <strong>javaMethod</strong> <em>(<var>methodname</var>, <var>obj</var>)</em><a href='#index-javaMethod' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javaMethod-1"><span class="category">: </span><span><em><var>ret</var> =</em> <strong>javaMethod</strong> <em>(<var>methodname</var>, <var>obj</var>, <var>arg1</var>, …)</em><a href='#index-javaMethod-1' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Invoke the method <var>methodname</var> on the Java object <var>obj</var> with the
arguments <var>arg1</var>, ….
</p>
<p>For static methods, <var>obj</var> can be a string representing the fully
qualified name of the corresponding class.
</p>
<p>When <var>obj</var> is a regular Java object, structure-like indexing can be
used as a shortcut syntax. For instance, the two following statements are
equivalent
</p>
<div class="example">
<pre class="example"> ret = javaMethod ("method1", x, 1.0, "a string")
ret = x.method1 (1.0, "a string")
</pre></div>
<p><code>javaMethod</code> returns the result of the method invocation.
</p>
<p><strong>See also:</strong> <a href="Creating-a-Class.html#XREFmethods">methods</a>, <a href="#XREFjavaObject">javaObject</a>.
</p></dd></dl>
<p>The following three functions are used to display and modify the class path
used by the Java Virtual Machine. This is entirely separate from Octave’s
<code>PATH</code> variable and is used by the JVM to find the correct code to execute.
</p>
<span id="index-classpath_002c-displaying"></span>
<span id="index-classpath_002c-dynamic"></span>
<span id="index-dynamic-classpath-1"></span>
<span id="index-classpath_002c-static"></span>
<span id="index-static-classpath-1"></span>
<span id="XREFjavaclasspath"></span><dl class="def">
<dt id="index-javaclasspath"><span class="category">: </span><span><em></em> <strong>javaclasspath</strong> <em>()</em><a href='#index-javaclasspath' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javaclasspath-1"><span class="category">: </span><span><em><var>dpath</var> =</em> <strong>javaclasspath</strong> <em>()</em><a href='#index-javaclasspath-1' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javaclasspath-2"><span class="category">: </span><span><em>[<var>dpath</var>, <var>spath</var>] =</em> <strong>javaclasspath</strong> <em>()</em><a href='#index-javaclasspath-2' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javaclasspath-3"><span class="category">: </span><span><em><var>clspath</var> =</em> <strong>javaclasspath</strong> <em>(<var>what</var>)</em><a href='#index-javaclasspath-3' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Return the class path of the Java virtual machine in the form of a cell
array of strings.
</p>
<p>If called with no inputs:
</p>
<ul>
<li> If no output is requested, the dynamic and static classpaths are
printed to the standard output.
</li><li> If one output value <var>dpath</var> is requested, the result is the
dynamic classpath.
</li><li> If two output values<var>dpath</var> and <var>spath</var> are requested, the
first variable will contain the dynamic classpath and the second will
contain the static classpath.
</li></ul>
<p>If called with a single input parameter <var>what</var>:
</p>
<dl compact="compact">
<dt><span><code>"-dynamic"</code></span></dt>
<dd><p>Return the dynamic classpath.
</p>
</dd>
<dt><span><code>"-static"</code></span></dt>
<dd><p>Return the static classpath.
</p>
</dd>
<dt><span><code>"-all"</code></span></dt>
<dd><p>Return both the static and dynamic classpath in a single cellstr.
</p></dd>
</dl>
<p><strong>See also:</strong> <a href="#XREFjavaaddpath">javaaddpath</a>, <a href="#XREFjavarmpath">javarmpath</a>.
</p></dd></dl>
<span id="index-javaaddpath"></span>
<span id="index-classpath_002c-adding-new-path"></span>
<span id="index-path_002c-adding-to-classpath"></span>
<span id="index-classpath_002c-dynamic-1"></span>
<span id="index-dynamic-classpath_002c-adding-new-path"></span>
<span id="XREFjavaaddpath"></span><dl class="def">
<dt id="index-javaaddpath-1"><span class="category">: </span><span><em></em> <strong>javaaddpath</strong> <em>(<var>clspath</var>)</em><a href='#index-javaaddpath-1' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javaaddpath-2"><span class="category">: </span><span><em></em> <strong>javaaddpath</strong> <em>(<var>clspath1</var>, …)</em><a href='#index-javaaddpath-2' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javaaddpath-3"><span class="category">: </span><span><em></em> <strong>javaaddpath</strong> <em>({<var>clspath1</var>, …})</em><a href='#index-javaaddpath-3' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javaaddpath-4"><span class="category">: </span><span><em></em> <strong>javaaddpath</strong> <em>(…, "-end")</em><a href='#index-javaaddpath-4' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Add <var>clspath</var> to the beginning of the dynamic class path of the
Java virtual machine.
</p>
<p><var>clspath</var> may either be a directory where <samp>.class</samp> files are
found, or a <samp>.jar</samp> file containing Java classes. Multiple paths may
be added at once by specifying additional arguments, or by using a cell
array of strings.
</p>
<p>If the final argument is <code>"-end"</code>, append the new element to the
end of the current classpath.
</p>
<p><strong>See also:</strong> <a href="#XREFjavarmpath">javarmpath</a>, <a href="#XREFjavaclasspath">javaclasspath</a>.
</p></dd></dl>
<span id="index-classpath_002c-removing-path"></span>
<span id="index-path_002c-removing-from-classpath"></span>
<span id="XREFjavarmpath"></span><dl class="def">
<dt id="index-javarmpath"><span class="category">: </span><span><em></em> <strong>javarmpath</strong> <em>(<var>clspath</var>)</em><a href='#index-javarmpath' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javarmpath-1"><span class="category">: </span><span><em></em> <strong>javarmpath</strong> <em>(<var>clspath1</var>, …)</em><a href='#index-javarmpath-1' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javarmpath-2"><span class="category">: </span><span><em></em> <strong>javarmpath</strong> <em>({<var>clspath1</var>, …})</em><a href='#index-javarmpath-2' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Remove <var>clspath</var> from the dynamic class path of the Java virtual
machine.
</p>
<p><var>clspath</var> may either be a directory where <samp>.class</samp> files are found,
or a <samp>.jar</samp> file containing Java classes. Multiple paths may be
removed at once by specifying additional arguments, or by using a cell array
of strings.
</p>
<p><strong>See also:</strong> <a href="#XREFjavaaddpath">javaaddpath</a>, <a href="#XREFjavaclasspath">javaclasspath</a>.
</p></dd></dl>
<p>The following functions provide information and control over the interface
between Octave and the Java Virtual Machine.
</p>
<span id="XREFjavachk"></span><dl class="def">
<dt id="index-javachk"><span class="category">: </span><span><em></em> <strong>javachk</strong> <em>(<var>feature</var>)</em><a href='#index-javachk' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javachk-1"><span class="category">: </span><span><em></em> <strong>javachk</strong> <em>(<var>feature</var>, <var>caller</var>)</em><a href='#index-javachk-1' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javachk-2"><span class="category">: </span><span><em><var>msg</var> =</em> <strong>javachk</strong> <em>(…)</em><a href='#index-javachk-2' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Check for the presence of the Java <var>feature</var> in the current session.
Return an error structure if <var>feature</var> is not available, not enabled,
or not recognized.
</p>
<p>Possible recognized features are:
</p>
<dl compact="compact">
<dt><span><code>"awt"</code></span></dt>
<dd><p>Abstract Window Toolkit for GUIs.
</p>
</dd>
<dt><span><code>"desktop"</code></span></dt>
<dd><p>Interactive desktop is running.
</p>
</dd>
<dt><span><code>"jvm"</code></span></dt>
<dd><p>Java Virtual Machine.
</p>
</dd>
<dt><span><code>"swing"</code></span></dt>
<dd><p>Swing components for lightweight GUIs.
</p></dd>
</dl>
<p>If <var>feature</var> is not supported, a scalar struct with field
<code>"message"</code> and <code>"identifier"</code> is returned. The field
<code>"message"</code> contains an error message mentioning <var>feature</var> as
well as the optional user-specified <var>caller</var>. This structure is
suitable for passing in to the <code>error</code> function.
</p>
<p>If <var>feature</var> is supported and available, an empty struct array is
returned with fields <code>"message"</code> and <code>"identifier"</code>.
</p>
<p><code>javachk</code> determines if specific Java features are available in an
Octave session. This function is provided for scripts which may alter
their behavior based on the availability of Java or specific Java runtime
features.
</p>
<p>Compatibility Note: The feature <code>"desktop"</code> is never available since
Octave has no Java-based desktop.
</p>
<p><strong>See also:</strong> <a href="#XREFusejava">usejava</a>, <a href="Raising-Errors.html#XREFerror">error</a>.
</p></dd></dl>
<span id="XREFusejava"></span><dl class="def">
<dt id="index-usejava"><span class="category">: </span><span><em></em> <strong>usejava</strong> <em>(<var>feature</var>)</em><a href='#index-usejava' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Return true if the Java element <var>feature</var> is available.
</p>
<p>Possible features are:
</p>
<dl compact="compact">
<dt><span><code>"awt"</code></span></dt>
<dd><p>Abstract Window Toolkit for GUIs.
</p>
</dd>
<dt><span><code>"desktop"</code></span></dt>
<dd><p>Interactive desktop is running.
</p>
</dd>
<dt><span><code>"jvm"</code></span></dt>
<dd><p>Java Virtual Machine.
</p>
</dd>
<dt><span><code>"swing"</code></span></dt>
<dd><p>Swing components for lightweight GUIs.
</p></dd>
</dl>
<p><code>usejava</code> determines if specific Java features are available in an
Octave session. This function is provided for scripts which may alter
their behavior based on the availability of Java. The feature
<code>"desktop"</code> always returns <code>false</code> as Octave has no Java-based
desktop. Other features may be available if Octave was compiled with the
Java Interface and Java is installed.
</p>
<p><strong>See also:</strong> <a href="#XREFjavachk">javachk</a>.
</p></dd></dl>
<span id="index-memory_002c-displaying-Java-memory-status"></span>
<span id="XREFjavamem"></span><dl class="def">
<dt id="index-javamem"><span class="category">: </span><span><em></em> <strong>javamem</strong> <em>()</em><a href='#index-javamem' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-javamem-1"><span class="category">: </span><span><em><var>jmem</var> =</em> <strong>javamem</strong> <em>()</em><a href='#index-javamem-1' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Show the current memory usage of the Java virtual machine (JVM) and run the
garbage collector.
</p>
<p>When no return argument is given the info is printed to the screen.
Otherwise, the output cell array <var>jmem</var> contains Maximum, Total, and
Free memory (in bytes).
</p>
<p>All Java-based routines are run in the JVM’s shared memory pool, a
dedicated and separate part of memory claimed by the JVM from your
computer’s total memory (which comprises physical RAM and virtual memory /
swap space on hard disk).
</p>
<p>The maximum allowable memory usage can be configured using the file
<samp>java.opts</samp>. The directory where this file resides is determined by
the environment variable <code><span class="nolinebreak">OCTAVE_JAVA_DIR</span></code><!-- /@w -->. If unset, the directory
where <samp>javaaddpath.m</samp> resides is used instead (typically
<samp><code><span class="nolinebreak">OCTAVE_HOME</span></code><!-- /@w -->/share/octave/<code><span class="nolinebreak">OCTAVE_VERSION</span></code><!-- /@w -->/m/java/</samp>).
</p>
<p><samp>java.opts</samp> is a plain text file with one option per line. The default
initial memory size and default maximum memory size (which are both system
dependent) can be overridden like so:
</p>
<p>-Xms64m
</p>
<p>-Xmx512m
</p>
<p>(in megabytes in this example).
You can adapt these values to your own requirements if your system has
limited available physical memory or if you get Java memory errors.
</p>
<p><code>"Total memory"</code> is what the operating system has currently assigned
to the JVM and depends on actual and active memory usage.
<code>"Free memory"</code> is self-explanatory. During operation of Java-based
Octave functions the amount of Total and Free memory will vary, due to
Java’s own cleaning up and your operating system’s memory management.
</p></dd></dl>
<span id="XREFjava_005fmatrix_005fautoconversion"></span><dl class="def">
<dt id="index-java_005fmatrix_005fautoconversion"><span class="category">: </span><span><em><var>val</var> =</em> <strong>java_matrix_autoconversion</strong> <em>()</em><a href='#index-java_005fmatrix_005fautoconversion' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-java_005fmatrix_005fautoconversion-1"><span class="category">: </span><span><em><var>old_val</var> =</em> <strong>java_matrix_autoconversion</strong> <em>(<var>new_val</var>)</em><a href='#index-java_005fmatrix_005fautoconversion-1' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-java_005fmatrix_005fautoconversion-2"><span class="category">: </span><span><em></em> <strong>java_matrix_autoconversion</strong> <em>(<var>new_val</var>, "local")</em><a href='#index-java_005fmatrix_005fautoconversion-2' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Query or set the internal variable that controls whether Java arrays are
automatically converted to Octave matrices.
</p>
<p>The default value is false.
</p>
<p>When called from inside a function with the <code>"local"</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p>
<p><strong>See also:</strong> <a href="#XREFjava_005funsigned_005fautoconversion">java_unsigned_autoconversion</a>, <a href="#XREFdebug_005fjava">debug_java</a>.
</p></dd></dl>
<span id="XREFjava_005funsigned_005fautoconversion"></span><dl class="def">
<dt id="index-java_005funsigned_005fautoconversion"><span class="category">: </span><span><em><var>val</var> =</em> <strong>java_unsigned_autoconversion</strong> <em>()</em><a href='#index-java_005funsigned_005fautoconversion' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-java_005funsigned_005fautoconversion-1"><span class="category">: </span><span><em><var>old_val</var> =</em> <strong>java_unsigned_autoconversion</strong> <em>(<var>new_val</var>)</em><a href='#index-java_005funsigned_005fautoconversion-1' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-java_005funsigned_005fautoconversion-2"><span class="category">: </span><span><em></em> <strong>java_unsigned_autoconversion</strong> <em>(<var>new_val</var>, "local")</em><a href='#index-java_005funsigned_005fautoconversion-2' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Query or set the internal variable that controls how integer classes are
converted when <code>java_matrix_autoconversion</code> is enabled.
</p>
<p>When enabled, Java arrays of class Byte or Integer are converted to matrices
of class uint8 or uint32 respectively. The default value is true.
</p>
<p>When called from inside a function with the <code>"local"</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p>
<p><strong>See also:</strong> <a href="#XREFjava_005fmatrix_005fautoconversion">java_matrix_autoconversion</a>, <a href="#XREFdebug_005fjava">debug_java</a>.
</p></dd></dl>
<span id="XREFdebug_005fjava"></span><dl class="def">
<dt id="index-debug_005fjava"><span class="category">: </span><span><em><var>val</var> =</em> <strong>debug_java</strong> <em>()</em><a href='#index-debug_005fjava' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-debug_005fjava-1"><span class="category">: </span><span><em><var>old_val</var> =</em> <strong>debug_java</strong> <em>(<var>new_val</var>)</em><a href='#index-debug_005fjava-1' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-debug_005fjava-2"><span class="category">: </span><span><em></em> <strong>debug_java</strong> <em>(<var>new_val</var>, "local")</em><a href='#index-debug_005fjava-2' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Query or set the internal variable that determines whether extra debugging
information regarding the initialization of the JVM and any Java exceptions
is printed.
</p>
<p>When called from inside a function with the <code>"local"</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p>
<p><strong>See also:</strong> <a href="#XREFjava_005fmatrix_005fautoconversion">java_matrix_autoconversion</a>, <a href="#XREFjava_005funsigned_005fautoconversion">java_unsigned_autoconversion</a>.
</p></dd></dl>
</div>
<hr>
<div class="header">
<p>
Previous: <a href="Set-up-the-JVM.html">Set up the JVM</a>, Up: <a href="Java-Interface.html">Java Interface</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|