1 This is octave-java.info, produced by makeinfo version 4.11 from
7 File: octave-java.info, Node: Top, Next: javaclasspath, Up: (dir)
9 1 Using Octave (and Matlab) with Java
10 *************************************
12 \r \r This description is based on the Octave package `java-1.2.8'. The
13 `java' package usually installs its script files (.m) in the directory
14 `.../share/Octave/packages/java-1.2.8' and its binary (.oct) files in
15 `.../libexec/Octave/packages/java-1.2.8'.
\r \r You can get help on
16 specific functions in Octave by executing the help command
\r with the
17 name of a function from this package:
\r
18 Octave > help javaObject
\r
19 \r You can view this help file in Octave by executing the info
20 command with
\r just the word java:
\r
24 Note on calling Octave from Java
25 ================================
27 The `java' package is designed for calling Java from Octave.
\r If you
28 want to call Octave from Java, you might want to use a library like
\r
29 `javaOctave' [http://kenai.com/projects/javaOctave] or
\r `joPas'
30 [http://jopas.sourceforge.net].
\r
35 \r Available Functions
\r
39 * javaclasspath:: get the class path of the JVM
\r
40 * javaaddpath:: add a path to the class path of the JVM
\r
41 * javarmpath:: remove a path to the class path of the JVM
\r
42 * javamem:: get information about available memory
\r
43 * javaArray:: create a Java array
\r
44 * javaObject:: create a Java object
\r
45 * java_new:: create a Java object
\r
46 * javaMethod:: invoke a method on the Java object
\r
47 * java_invoke:: invoke a method on the Java object
\r
48 * java_get:: get a field on the Java object
\r
49 * java_set:: set a field on the Java object
\r
50 * javamethods:: list the available methods of a Java objects
\r
51 * javafields:: list the available fields of a Java objects
\r
52 * msgbox:: display a dialog box
\r
53 * errordlg:: display a dialog with an error symbol
\r
54 * listdlg:: display a dialog with a selection list
\r
55 * warndlg:: display a dialog with a warning symbol
\r
56 * helpdlg:: display a dialog with a help symbol
\r
57 * inputdlg:: display a dialog with edit fields
\r
58 * questdlg:: display a dialog with a question icon
\r
60 Frequently Asked Questions
64 * How to distinguish between Octave and Matlab?::
\r
65 * How to make Java classes available?::
\r
66 * How to create an instance of a Java class?::
\r
67 * How can I handle memory limitations?::
\r
68 * How to compile the java package in Octave?::
\r
69 * Which TeX symbols are implemented in the dialog functions?::
\r
76 File: octave-java.info, Node: javaclasspath, Next: javaaddpath, Prev: Top, Up: Top
85 -- Function file: javaclasspath
86 -- Function file: STATIC = javaclasspath
87 -- Function file: [STATIC, DYNAMIC] = javaclasspath
88 -- Function file: PATH = javaclasspath (WHAT)
89 \r Return the class path of the Java virtual machine as a cell
90 array of strings.
\r \r If called without an input parameter:
\r
91 * If no output variable is given, the result is simply printed
92 \r to the standard output.
\r
94 * If one output variable STATIC is given, the result is
\r the
97 * If two output variables STATIC and DYNAMIC are
\r given, the
98 first variable will contain the static classpath,
\r the
99 second will be filled with the dynamic claspath.
\r
100 \r If called with a single input parameter WHAT:
\r
101 If no output parameter is given:
\r
103 * The result is printed to the standard output similar to the
104 call without input parameter.
105 \r If the output parameter PATH is used:
\r
107 * If WHAT is '-static' the static classpath is returned.
\r
109 * If WHAT is '-dynamic' the dynamic classpath is returned.
\r
111 * If WHAT is '-all' the static and the dynamic classpath
\r are
112 returned in a single cell array.
\r
113 \r For the example two entries have been added to the static
114 classpath using the file `classpath.txt'.
\r \r Example:
\r
115 Octave > javaclasspath('-all')
\r
119 z:/classdir/classfiles
\r
124 Octave > javaaddpath('z:/dynamic');
\r
125 Octave > ps = javaclasspath('-all')
\r
128 [1,1] = z:/someclasses.jar
\r
129 [1,2] = z:/classdir/classfiles
\r
134 *See also:* *note javaaddpath: doc-javaaddpath,
\r *note
135 javarmpath: doc-javarmpath,
\r *note How to make Java
136 classes available to Octave?: doc-FAQ.
\r
140 File: octave-java.info, Node: javaaddpath, Next: javarmpath, Prev: javaclasspath, Up: Top
147 -- Function File: javaaddpath (PATH)
148 \r Add PATH to the dynamic class path of the Java virtual machine.
149 PATH can be either a directory where .class files can be found, or
150 a .jar file containing Java classes. In both cases the directory
151 or file must exist.
\r \r Example:
\r \r This example adds a Java
152 archive and a directory containing .CLASS files to the CLASSPATH
153 and displays the current CLASSPATH list.
\r \r
154 Octave > javaaddpath('C:/java/myclasses.jar');
\r
155 Octave > javaaddpath('C:/java/classes');
\r
156 Octave > javaclasspath;
\r
159 [1,1] = C:\java\myclasses.jar
\r
160 [1,2] = C:\java\classes
\r
163 *See also:* *note javaclasspath: doc-javaclasspath, *note
164 javarmpath: doc-javarmpath,
\r *note How to make Java
165 classes available to Octave?: doc-FAQ.
\r
169 File: octave-java.info, Node: javarmpath, Next: javamem, Prev: javaaddpath, Up: Top
176 -- Function File: javarmpath (PATH)
177 Remove PATH from the dynamic class path of the Java virtual
178 machine. PATH can be either a directory where .class files can be
179 found, or a .jar file containing Java classes.
\r \r Example: This
180 example removes one of the directories added in the example for
181 the `javaaddpath' function.
\r \r
182 Octave > javarmpath('C:/java/classes');
\r
183 Octave > javaclasspath
\r
185 [1,1] = C:\java\myclasses.jar
\r
189 *See also:* *note javaaddpath: doc-javaaddpath, *note
190 javaclasspath: doc-javaclasspath,
\r *note How to make
191 Java classes available to Octave?: doc-FAQ.
\r
195 File: octave-java.info, Node: javamem, Next: javaArray, Prev: javarmpath, Up: Top
202 -- Function File: javamem
203 -- Function File: [JMEM] = javamem
204 \r Show current memory status of the java virtual machine (JVM)
\r
205 & run garbage collector.
\r \r When no return argument is given the
206 info is echoed to the screen.
\r Otherwise, cell array JMEM
207 contains MAXIMUM, TOTAL, and
\r FREE memory (in bytes).
\r \r All
208 java-based routines are run in the JVM's shared memory pool,
\r a
209 dedicated and separate part of memory claimed by the JVM from
\r
210 your computer's total memory (which comprises physical RAM and
\r
211 virtual memory / swap space on hard disk).
\r \r The maximum
212 available memory can be set using the file `java.opts'
\r (in the
213 same subdirectory where `javaaddpath.m' lives, see
\r `which
214 javaaddpath'. Usually that is:
215 \r [/usr]/share/Octave/packages/java-1.2.8.
\r \r `java.opts' is a
216 plain text file. It can contain memory related
\r options,
217 starting with `-X'.
\r In the following exmaple, the first line
218 specifies the initial
\r memory size in megabytes, the second line
219 specifies the requested
\r maximum size:
\r
222 You can adapt these values if your system has limited available
\r
223 physical memory. When no `java.opts' file is present, the default
\r
224 assignments are depending on system hardware and Java version.
\r
225 Typically these are an initial memory size of RAM/64 and
\r a
226 maximum memory size of MIN(RAM/4, 1GB), where RAM
\r is the amount
227 of installed memory.
\r \r In the output of javamem TOTAL MEMORY is
228 what the operating
\r system has currently assigned to the JVM and
229 depends on actual
\r and active memory usage.
\r FREE MEMORY is
230 self-explanatory. During operation of java-based
\r Octave
231 functions the amounts of Total and Free memory will vary,
\r due to
232 java's own cleaning up and your operating system's memory
\r
233 management.
\r \r Example:
\r
235 Java virtual machine (JVM) memory info:
\r
236 Maximum available memory: 247 MB;
\r
237 (...running garbage collector...)
\r
238 OK, current status:
\r
239 Total memory in virtual machine: 15 MB;
\r
240 Free memory in virtual machine: 15 MB;
\r
243 Octave > [MEM] = javamem()
\r
252 *See also:* *note How can I handle memory limitations?: doc-FAQ.
\r
256 File: octave-java.info, Node: javaArray, Next: javaObject, Prev: javamem, Up: Top
263 -- Function File: ARRAY = javaArray (CLASS, [M, N, ...])
264 -- Function File: ARRAY = javaArray (CLASS, M, N, ...)
265 \r Create a Java array of size `[M, N, ...]' with elements of
266 class CLASS. CLASS can be a Java object representing a class or a
267 string containing the fully qualified class name.
\r The generated
268 array is uninitialized, all elements are set to null if CLASS is a
269 reference type, or to a default value (usually 0) if CLASS is a
270 primitive type.
\r \r Example: This example creates a (2 x 2)
271 array of Java STRING objects and assigns a value to one of the
272 elements. Finally it displays the type of A.
\r
273 Octave > a = javaArray('java.lang.String', 2, 2);
\r
274 Octave > a(1,1) = 'Hello';
\r
277 <Java object: java.lang.String[][]>
\r
281 File: octave-java.info, Node: javaObject, Next: java_new, Prev: javaArray, Up: Top
288 -- Function File: OBJECT = javaObject (CLASS, [ARG1, ..., ARGN])
289 \r Create a Java object of class CLASS, by calling the class
290 constructor with the given arguments ARG1, ..., ARGN. The CLASS
291 name should be given in fully qualified string form (including any
292 package prefix). In Matlab you should avoid to use the import
293 statement and the short form of object creation.
\r \r Example:
294 This example demonstrates two ways to create a Java `StringBuffer'
295 object. The first variant creates an uninitialized STRINGBUFFER
296 object, while the second variant calls a constructor with the
297 given initial `String'. Then it displays the type of `o', and
298 finally the content of the `StringBuffer' object is displayed by
299 using its `toString' method.
\r \r
300 Octave > o = javaObject('java.lang.StringBuffer');
\r
301 Octave > o = javaObject('java.lang.StringBuffer', 'Initial');
\r
304 <Java object: java.lang.StringBuffer>
\r
305 Octave > o.toString
\r
307 \r Equivalent to the `java_new' function.
\r For compatibility with
308 Matlab it is recommended to use the `javaObject' function.
\r \r
310 *See also:* *note java_new: doc-java_new.
\r
314 File: octave-java.info, Node: java_new, Next: javaMethod, Prev: javaObject, Up: Top
321 -- Function File: OBJECT = java_new (CLASS, [ARG1, ..., ARGN])
322 \r Create a Java object of class CLASS, by calling the class
323 constructor with the given arguments ARG1, ..., ARGN.
\r
324 Equivalent to the `javaObject' function.
\r For compatibility with
325 Matlab it is recommended to use the `javaObject' function.
\r \r
327 Octave > o = java_new('java.lang.StringBuffer', 'Initial');
\r
330 <Java object: java.lang.StringBuffer>
\r
331 Octave > o.toString
\r
335 *See also:* *note javaObject: doc-javaObject.
\r
339 File: octave-java.info, Node: javaMethod, Next: java_invoke, Prev: java_new, Up: Top
346 -- Function File: RET = javaMethod (NAME, OBJECT[, ARG1, ..., ARGN])
347 \r Invoke the method NAME on the Java object OBJECT with the
348 arguments ARG1, ... For static methods, OBJECT can be a string
349 representing the fully qualified name of the corresponding class.
350 The function returns the result of the method invocation.
\r When
351 OBJECT is a regular Java object, the structure-like indexing can
352 be used as a shortcut syntax. For instance, the two statements in
353 the example are equivalent.
\r \r Example:
\r
354 Octave > ret = javaMethod("method1", x, 1.0, "a string")
\r
355 Octave > ret = x.method1(1.0, "a string")
\r
358 *See also:* *note javamethods: doc-javamethods.
\r
362 File: octave-java.info, Node: java_invoke, Next: java_get, Prev: javaMethod, Up: Top
369 -- Function File: RET = java_invoke (OBJECT, NAME[, ARG1, ..., ARGN])
370 \r Invoke the method NAME on the Java object OBJECT with the
371 arguments ARG1, ... For static methods, OBJECT can be a string
372 representing the fully qualified name of the corresponding class.
373 The function returns the result of the method invocation.
374 Equivalent to the `javaMethod' function. When OBJECT is a regular
375 Java object, the structure-like indexing can be used as a shortcut
376 syntax. For instance, the two statements in the example are
377 equivalent.
\r \r Example:
\r
378 Octave > ret = java_invoke(x, "method1", 1.0, "a string")
\r
379 Octave > ret = x.method1(1.0, "a string")
\r
382 *See also:* *note javamethods: doc-javamethods.
\r
386 File: octave-java.info, Node: java_get, Next: java_set, Prev: java_invoke, Up: Top
393 -- Function File: VAL = java_get (OBJECT, NAME)
394 \r Get the value of the field NAME of the Java object OBJECT. For
395 static fields, OBJECT can be a string representing the fully
396 qualified name of the corresponding class.
\r \r When OBJECT is a
397 regular Java object, the structure-like indexing can be used as a
398 shortcut syntax. For instance, the two statements in the example
399 are equivalent
\r \r Example:
\r
400 Octave > java_get(x, "field1")
\r
404 *See also:* *note javafields: doc-javafields,
\r *note
405 java_set: doc-java_set.
\r
409 File: octave-java.info, Node: java_set, Next: javamethods, Prev: java_get, Up: Top
416 -- Function File: OBJECT = java_set (OBJECT, NAME, VALUE)
417 \r Set the value of the field NAME of the Java object OBJECT to
418 VALUE. For static fields, OBJECT can be a string representing the
419 fully qualified named of the corresponding Java class.
\r When
420 OBJECT is a regular Java object, the structure-like indexing can
421 be used as a shortcut syntax. For instance, the two statements in
422 the example are equivalent
\r \r Example:
\r
423 Octave > java_set(x, "field1", val)
\r
424 Octave > x.field1 = val
\r
427 *See also:* *note javafields: doc-javafields,
\r *note
428 java_get: doc-java_get.
\r
432 File: octave-java.info, Node: javamethods, Next: javafields, Prev: java_set, Up: Top
439 -- Function File: M = javamethods (CLASSNAME)
440 -- Function File: M = javamethods (OBJECT)
441 \r Given a string with a Java class name CLASSNAME or a regular
442 Java object OBJECT, this function returns a cell array containing
443 descriptions of all methods of the Java class CLASSNAME
444 respectively the class of OBJECT.
\r \r Examples: The first
445 example shows how the methods of a class can be queried, while the
446 second example works with the methods of a concrete instance of a
447 class. Note that creation of a `java.lang.Double' object requires
448 an initializer (in the example the value 1.2).
\r
449 Octave > m = javamethods('java.lang.Double');
\r
455 ans = double longBitsToDouble(long)
\r
457 Octave > o = javaObject('java.lang.Double', 1.2);
\r
458 Octave > m = javamethods(o);
\r
464 ans = double longBitsToDouble(long)
\r
467 *See also:* *note javafields: doc-javafields,
\r *note
468 java_invoke: doc-java_invoke.
\r
472 File: octave-java.info, Node: javafields, Next: msgbox, Prev: javamethods, Up: Top
479 -- Function File: F = javafields (CLASSNAME)
480 -- Function File: F = javafields (OBJECT)
481 \r Given a string with a Java class name CLASSNAME or a regular
482 Java object OBJECT, this function returns a cell array containing
483 the descriptions for all fields of the Java class CLASSNAME
484 respectively the class of OBJECT.
\r \r Examples:
\r \r The first
485 example shows how the fields of a class can be queried without
486 creating an instance of the class.
\r
487 Octave > f = javafields('java.lang.Double');
\r
493 ans = public static final int java.lang.Double.MAX_EXPONENT
\r
494 \r The second example works with the fields of an instance of a
495 class. Note that creation of a `java.lang.Double' object requires
496 an initializer (in the example a value of 1.2 is specified).
\r
497 Octave > o = javaObject('java.lang.Double', 1.2);
\r
498 Octave > f = javafields(o);
\r
504 ans = public static final int java.lang.Double.MAX_EXPONENT
\r
507 *See also:* *note java_set: doc-java_set,
\r *note
508 java_get: doc-java_get.
\r
512 File: octave-java.info, Node: msgbox, Next: errordlg, Prev: javafields, Up: Top
519 -- Function File: F = msgbox (MESSAGE)
520 -- Function File: F = msgbox (MESSAGE, TITLE)
521 -- Function File: F = msgbox (MESSAGE, TITLE, ICON)
522 \r Displays a MESSAGE using a dialog box. The parameter TITLE can
523 be used to optionally decorate the dialog caption.
\r The third
524 optional parameter ICON can be either `'error'', `'help'' or
525 `'warn''
\r and selectes the corresponding icon.
\r If it is
526 omitted, no icon is shown.
\r \r Examples: The first example shows
527 a dialog box without a caption text, whereas the second example
528 specifies a caption text of its own.
\r The third example also
529 demonstrates how a character
\r according to the TeX symbol set
530 can be specified. It is important to include a space character
\r
531 after the symbol code and how to embed a newline character (ASCII
532 code 10) into the string.
\r \r
533 Octave > msgbox('This is an important message');
\r
534 Octave > msgbox('Do not forget to feed the cat.', 'Remember');
\r
535 Octave > msgbox(['I \heartsuit Octave!',10, ...
\r
536 ' Even if I hate it sometimes.'], ...
\r
537 'I Confess','warn');
\r
538 \r \0\b[image src="images/image003.png"
\0\b]
\r \r
540 *See also:* *note errordlg: doc-errordlg,
\r *note
541 helpdlg: doc-helpdlg,
\r *note warndlg: doc-warndlg.
\r
545 File: octave-java.info, Node: errordlg, Next: helpdlg, Prev: msgbox, Up: Top
552 -- Function File: F = errordlg (MESSAGE)
553 -- Function File: F = errordlg (MESSAGE, TITLE)
554 \r Displays the MESSAGE using an error dialog box. The TITLE can
555 be used optionally to decorate the dialog caption instead of the
556 default title "Error Dialog".
\r \r Examples: The first example
557 shows a dialog box with default caption, whereas the second
558 example specifies a its own caption
\r
559 Octave > errordlg('Oops, an expected error occured');
\r
560 \0\b[image src="images/image001.png"
\0\b]
\r
561 Octave > errordlg('Another error occured', 'Oops');
\r
564 *See also:* *note helpdlg: doc-helpdlg,
\r *note inputdlg:
565 doc-inputdlg,
\r *note listdlg: doc-listdlg,
\r
566 *note questdlg: doc-questdlg,
\r *note warndlg:
571 File: octave-java.info, Node: helpdlg, Next: inputdlg, Prev: errordlg, Up: Top
578 -- Function File: F = helpdlg (MESSAGE)
579 -- Function File: F = helpdlg (MESSAGE, TITLE)
580 \r Displays the MESSAGE using a help dialog box. The help message
581 can consist of multiple lines, separated by a newline character.
582 The TITLE can be used optionally to decorate the dialog caption
583 bar instead of the default title "Help Dialog".
\r \r Examples:
584 The first example shows a dialog box with default caption, whereas
585 the next two examples specify their own caption. Note that if the
586 backslash escape notation is used in a double quoted string, it is
587 immediately replaced by Octave with a newline.
\r If it is
588 contained in a single quoted string, it is not replaced by Octave,
589 \r but later by the dialog function.
\r \r
590 Octave > helpdlg('This is a short notice');
\r
591 Octave > helpdlg(['line #1',10,'line #2'], 'Inventory');
\r
592 Octave > helpdlg("1 eel\n9 buckazoids\n2 peas", 'Inventory');
\r
593 \r \0\b[image src="images/image004.png"
\0\b]
\r \r
595 *See also:* *note errordlg: doc-errordlg,
\r *note
596 inputdlg: doc-inputdlg,
\r *note listdlg: doc-listdlg,
\r
597 *note questdlg: doc-questdlg,
\r *note warndlg:
602 File: octave-java.info, Node: inputdlg, Next: listdlg, Prev: helpdlg, Up: Top
609 -- Function File: C = inputdlg (PROMPT)
610 -- Function File: C = inputdlg (PROMPT, TITLE)
611 -- Function File: C = inputdlg (PROMPT, TITLE, ROWSCOLS)
612 -- Function File: C = inputdlg (PROMPT, TITLE, ROWSCOLS, DEFAULTS)
613 \r Returns the user's inputs from a multi-textfield dialog box in
614 form of a cell array of strings. If the user closed the dialog
615 with the Cancel button, en empty cell array is returned. This can
616 be checked with the ISEMPTY function. The first argument PROMPT is
617 mandatory. It is a cell array with strings labeling each text
618 field. The optional string TITLE can be used as the caption of the
619 dialog. The size of the text fields can be defined by the argument
620 ROWSCOLS, which can be either a scalar to define the number of
621 columns used for each text field, a vector to define the number of
622 rows for each text field individually, or a matrix to define the
623 number of rows and columns for each text field individually. It is
624 possible to place default values into the text fields by supplying
625 a cell array of strings for the argument DEFAULTS.
\r \r Examples:
626 The first example shows a simple usage of the input dialog box
628 Octave > prompt = {'Width','Height','Depth'};
\r
629 Octave > dims = inputdlg(prompt, 'Enter Box Dimensions');
\r
630 Octave > volume = str2num(dims{1}) * ...
\r
631 str2num(dims{2}) * str2num(dims{3});
\r
632 \r \0\b[image src="images/image005.png"
\0\b]
\r \r The second
633 example shows the application of a scalar for the number of rows
634 and a cell array with default values.
\r
635 Octave > prompt = {'Width', 'Height', 'Depth'};
\r
636 Octave > defaults = {'1.1', '2.2', '3.3'};
\r
637 Octave > title = 'Enter Box Dimensions';
\r
638 Octave > dims = inputdlg(prompt, title, 1, defaults);
\r
646 \r \0\b[image src="images/image006.png"
\0\b]
\r \r The third
647 example shows the application of row height and column width
649 Octave > prompt = {'Width', 'Height', 'Depth'};
\r
650 Octave > defaults = {'1.1', '2.2', '3.3'};
\r
651 Octave > rc = [1,10; 2,20; 3,30];
\r
652 Octave > title = 'Enter Box Dimensions';
\r
653 Octave > dims = inputdlg(prompt, title, rc, defaults);
\r
654 \r \0\b[image src="images/image007.png"
\0\b]
\r \r
656 *See also:* *note errordlg: doc-errordlg,
\r *note
657 helpdlg: doc-helpdlg,
\r *note listdlg: doc-listdlg,
\r
658 *note questdlg: doc-questdlg,
\r *note warndlg:
663 File: octave-java.info, Node: listdlg, Next: questdlg, Prev: inputdlg, Up: Top
670 -- Function File: [SEL, OK] = listdlg (KEY, VALUE[, KEY, VALUE, ...])
671 \r This function returns the inputs from a list dialog box. The
672 result is returned as a vector of indices and a flag. The vector
673 SEL contains the 1-based indices of all list items selected by the
674 user. The flag OK is 1 if the user closed the dialog with the OK
675 Button, otherwise it is 0 and SEL is empty.. The arguments of this
676 function are specified in the form of KEY, VALUE pairs. At least
677 the `'ListString'' argument pair must be specified. It is also
678 possible to preselect items in the list in order to provide a
679 default selection.
\r \r The KEY and VALUE pairs can be selected
680 from the following list:
\r \r
682 a cell array of strings comprising the content of the list.
\r
685 can be either `'single'' or `'multiple''.
\r
688 a vector with two elements `[width, height]' defining the
689 size of the list field in pixels.
\r
692 a vector containing 1-based indices of preselected elements.
\r
695 a string to be used as the dialog caption.
\r
698 a cell array of strings to be displayed above the list
702 a string used to label the OK button.
\r
705 a string used to label the Cancel button.
\r
707 Octave > [s,ok] = listdlg('ListString', ...
\r
708 {'An item', 'another', 'yet another'}, ...
\r
709 'Name', 'Selection Dialog', ...
\r
710 'SelectionMode', 'Multiple', ...
\r
711 'PromptString',['Select an item...',10,'...or multiple items']);
\r
713 Octave > imax = length(s);
\r
714 Octave > for i=1:1:imax
\r
715 Octave > disp(s(i));
\r
717 \r \0\b[image src="images/image002.png"
\0\b]
\r \r
719 *See also:* *note errordlg: doc-errordlg,
\r *note
720 helpdlg: doc-helpdlg,
\r *note inputdlg: doc-inputdlg,
\r
721 *note questdlg: doc-questdlg,
\r *note warndlg:
726 File: octave-java.info, Node: questdlg, Next: warndlg, Prev: listdlg, Up: Top
733 -- Function File: C = questdlg (MESSAGE, TITLE)
734 -- Function File: C = questdlg (MESSAGE, TITLE, DEFAULT)
735 -- Function File: C = questdlg (MESSAGE, TITLE, BTN1, BTN2, DEFAULT)
736 -- Function File: C = questdlg (MESSAGE, TITLE, BTN1, BTN2, BTN3,
738 \r Displays the MESSAGE using a question dialog box with a caption
739 TITLE. The dialog contains two or three buttons which all close
740 the dialog. It returns the caption of the activated button.
\r \r
741 If only MESSAGE and TITLE are specified, three buttons with the
742 default captions "Yes",
\r "No", "Cancel" are used.
\r The string
743 DEFAULT identifies the default button, which is activated by
744 pressing the ENTER key. It must match one of the strings given in
745 BTN1, BTN2 or BTN3. If only two button captions BTN1 and BTN2 are
746 specified, the dialog will have only these two buttons.
\r \r \r
747 Examples: The first example shows a dialog box with two buttons,
748 whereas the next example demonstrates the use of three buttons.
\r
749 Octave > questdlg('Select your gender', 'Sex', ...
\r
750 'Male', 'Female', 'Female');
\r
751 \r \0\b[image src="images/image008.png"
\0\b]
\r \r
752 Octave > questdlg('Select your gender', 'Sex', ...
\r
753 'Male', 'dont know', 'Female', 'Female');
\r
754 \r \0\b[image src="images/image009.png"
\0\b]
\r \r
756 *See also:* *note errordlg: doc-errordlg,
\r *note
757 helpdlg: doc-helpdlg,
\r *note inputdlg: doc-inputdlg,
\r
758 *note listdlg: doc-listdlg,
\r *note warndlg:
763 File: octave-java.info, Node: warndlg, Next: How to distinguish between Octave and Matlab?, Prev: questdlg, Up: Top
770 -- Function File: F = warndlg (MESSAGE)
771 -- Function File: F = warndlg (MESSAGE, TITLE)
772 \r Displays a MESSAGE using a warning dialog box. The TITLE can be
773 used optionally to decorate the dialog caption instead of the
774 default title "Warning Dialog".
\r \r Examples: The first example
775 shows a dialog box with default caption, whereas the second
776 example specifies a caption text of its own. The second example
777 also demonstrates how a character
\r according to the TeX symbol
778 set can be specified. It is important to include a space
779 character
\r after the symbol code. The \n character can be used to
780 start a new line.
\r The third example shows an alternate way to
781 embed the newline character (the newline character has the ASCII
782 code 10) into the string.
\r Please refer to the Octave manual for
783 the difference between single and double quoted
\r strings.
\r \r
784 Octave > warndlg('An expected warning occured');
\r
785 Octave > warndlg('I \heartsuit Octave!\nEven if I hate her sometimes.', ...
\r
787 Octave > warndlg(['I \heartsuit Octave!',10, ...
\r
788 ' Even if I hate her sometimes.'], ...
\r
790 \r \0\b[image src="images/image003.png"
\0\b]
\r \r
792 *See also:* *note errordlg: doc-errordlg,
\r *note
793 helpdlg: doc-helpdlg,
\r *note inputdlg: doc-inputdlg,
\r
794 *note listdlg: doc-listdlg,
\r *note questdlg:
798 4 FAQ - Frequently asked Questions
799 **********************************
802 File: octave-java.info, Node: How to distinguish between Octave and Matlab?, Next: How to make Java classes available?, Prev: warndlg, Up: Top
804 4.1 How to distinguish between Octave and Matlab?
805 =================================================
807 \r Octave and Matlab are very similar, but handle Java slightly
808 different. Therefore it may be necessary to detect the environment and
809 use the appropriate functions. The following function can be used to
810 detect the environment. Due to the persistent variable it can be called
811 repeatedly without a heavy performance hit.
\r \r Example:
\r
813 %% Return: true if the environment is Octave.
\r
815 function ret = isOctave
\r
816 persistent retval; % speeds up repeated calls
\r
819 retval = (exist('Octave_VERSION','builtin') > 0);
\r
827 File: octave-java.info, Node: How to make Java classes available?, Next: How to create an instance of a Java class?, Prev: How to distinguish between Octave and Matlab?, Up: Top
829 4.2 How to make Java classes available to Octave?
830 =================================================
832 \r Java finds classes by searching a CLASSPATH. This is a list of Java
833 archive files and/or directories containing class files.
\r In Octave
834 and Matlab the CLASSPATH is composed of two parts:
\r
835 * the STATIC CLASSPATH is initialized once at startup of the JVM,
838 * the DYNAMIC CLASSPATH which can be modified at runtime.
\r
839 Octave searches the STATIC CLASSPATH first, then the DYNAMIC
840 CLASSPATH.
\r Classes appearing in the STATIC as well as in the DYNAMIC
841 CLASSPATH will therefore be found in the STATIC CLASSPATH and loaded
842 from this location.
\r
843 \r Classes which shall be used regularly or must be available to all
844 users should be
\r added to the STATIC CLASSPATH.
\r The STATIC
845 CLASSPATH is populated once from the contents of a plain text file
846 named `classpath.txt' when the Java Virtual Machine starts. This file
847 contains one line for each individual classpath to be added to the
848 STATIC CLASSPATH.
\r These lines can identify single class files,
849 directories containing class files or Java archives with complete class
850 file hierarchies.
\r Comment lines starting with a `#' or a `%'
851 character are ignored.
\r \r The search rules for the file
852 `classpath.txt' are:
\r
853 * First, Octave searches for the file `classpath.txt' in your home
854 directory,
\r If such a file is found, it is read and defines the
855 initial STATIC CLASSPATH.
\r Thus it is possible to build an
856 initial static classpath on a 'per user' basis.
\r \r
858 * Next, Octave looks for another file `classpath.txt' in the package
859 installation directory.
\r This is where `javaclasspath.m' resides,
860 usually something like `...\share\Octave\packages\java-1.2.8'.
\r
861 You can find this directory by executing the command
\r
863 If this file exists, its contents is also appended to the static
864 classpath.
\r Note that the archives and class directories defined
865 in this file will affect all users.
\r
866 \r Classes which are used only by a specific script should be placed
867 in the DYNAMIC CLASSPATH. This portion of the classpath can be modified
868 at runtime using the `javaaddpath' and `javarmpath' functions.
\r \r
870 Octave > base_path = 'C:/Octave/java_files';
\r
872 Octave > % add two JARchives to the dynamic classpath
\r
873 Octave > javaaddpath([base_path, '/someclasses.jar']);
\r
874 Octave > javaaddpath([base_path, '/moreclasses.jar']);
\r
876 Octave > % check the dynamic classpath
\r
877 Octave > p = javaclasspath;
\r
878 Octave > disp(p{1});
\r
879 C:/Octave/java_files/someclasses.jar
\r
880 Octave > disp(p{2});
\r
881 C:/Octave/java_files/moreclasses.jar
\r
883 Octave > % remove the first element from the classpath
\r
884 Octave > javarmpath([base_path, '/someclasses.jar']);
\r
885 Octave > p = javaclasspath;
\r
886 Octave > disp(p{1});
\r
887 C:/Octave/java_files/moreclasses.jar
\r
889 Octave > % provoke an error
\r
890 Octave > disp(p{2});
\r
891 error: A(I): Index exceeds matrix dimension.
\r
892 \r Another way to add files to the DYNAMIC CLASSPATH exclusively for
893 your user account is to use the file `.octaverc' which is stored in
894 your home directory.
\r All Octave commands in this file are executed
895 each time you start a new instance of Octave.
\r The following example
896 adds the directory `octave' to Octave's search path and
\r the archive
897 `myclasses.jar' in this directory to the Java search path.
\r
898 % content of .octaverc:
\r
899 addpath('~/octave');
\r
900 javaaddpath('~/octave/myclasses.jar');
\r
904 File: octave-java.info, Node: How to create an instance of a Java class?, Next: How can I handle memory limitations?, Prev: How to make Java classes available?, Up: Top
906 4.3 How to create an instance of a Java class?
907 ==============================================
909 \r If your code shall work under Octave as well as Matlab you should
910 use the function `javaObject' to create Java objects. The function
911 `java_new' is Octave specific and does not exist in the Matlab
912 environment.
\r \r Example 1, suitable for Octave but not for Matlab:
\r
913 Passenger = java_new('package.FirstClass', row, seat);
\r
914 \r Example 2, which works in Octave as well as in Matlab:
\r
915 Passenger = javaObject('package.FirstClass', row, seat);
\r
919 File: octave-java.info, Node: How can I handle memory limitations?, Next: How to compile the java package in Octave?, Prev: How to create an instance of a Java class?, Up: Top
921 4.4 How can I handle memory limitations?
922 ========================================
924 \r In order to execute Java code Octave creates a Java Virtual Machine
925 (JVM). Such a JVM allocates a fixed amount of initial memory and may
926 expand this pool up to a fixed maximum memory limit. The default values
927 depend on the Java version (see *note javamem: doc-javamem.).
\r The
928 memory pool is shared by all Java objects running in the JVM.
\r This
929 strict memory limit is intended mainly to avoid that runaway
930 applications inside web browsers or in enterprise servers can consume
931 all memory and crash the system.
\r When the maximum memory limit is
932 hit, Java code will throw exceptions so that applications will fail or
933 behave unexpectedly.
\r \r In Octave as well as in Matlab, you can
934 specify options for the creation of the JVM inside a file named
935 `java.opts'.
\r This is a text file where you can enter lines
936 containing `-X' and `-D' options handed to the JVM during
937 initialization.
\r \r In Octave, the Java options file must be located
938 in the directory where `javaclasspath.m' resides, i.e. the package
939 installation directory, usually something like
940 ...\SHARE\OCTAVE\PACKAGES\JAVA-1.2.8. You can find this directory by
943 \r In Matlab, the options file goes into the MATLABROOT/BIN/ARCH
944 directory or in your personal Matlab startup directory (can be
945 determined by a `pwd' command). MATLABROOT is the Matlab root directory
946 and ARCH is your system architecture, which you find by issuing the
947 commands `matlabroot' respectively `computer('arch')'.
\r \r The `-X'
948 options allow you to increase the maximum amount of memory available to
949 the JVM to 256 Megabytes by adding the following line to the
952 \r The maximum possible amount of memory depends on your system. On
953 a Windows system with 2 Gigabytes main memory you should be able to set
954 this maximum to about 1 Gigabyte.
\r \r If your application requires a
955 large amount of memory from the beginning, you can also specify the
956 initial amount of memory allocated to the JVM. Adding the following
957 line to the `java.opts' file starts the JVM with 64 Megabytes of
960 \r For more details on the available `-X' options of your Java
961 Virtual Machine issue the command `java -X' at the operating system
962 command prompt and consult the Java documentation.
\r \r \r The `-D'
963 options can be used to define system properties which can then be used
964 by Java classes inside Octave. System properties can be retrieved by
965 using the `getProperty()' methods of the `java.lang.System' class. The
966 following example line defines the property MYPROPERTY and assigns it
967 the string `12.34'.
\r
969 The value of this property can then be retrieved as a string by a
970 Java object or in Octave:
\r
971 Octave > javaMethod('java.lang.System', 'getProperty', 'MyProperty');
\r
975 *See also:* *note javamem: doc-javamem.
\r \r
978 File: octave-java.info, Node: How to compile the java package in Octave?, Next: Which TeX symbols are implemented in the dialog functions?, Prev: How can I handle memory limitations?, Up: Top
980 4.5 How to compile the java package in Octave?
981 ==============================================
983 \r Most Octave installations come with the JAVA package pre-installed.
984 In case you want to replace this package with a more recent version,
985 you must perform the following steps:
\r \r
987 4.5.1 Uninstall the currently installed package JAVA
988 ----------------------------------------------------
990 Check whether the JAVA package is already installed by issuing
\r the
991 `pkg list' command:
\r
993 Package Name | Version | Installation directory
\r
994 --------------+---------+-----------------------
\r
995 java *| 1.2.8 | /home/octavio/octave/java-1.2.8
\r
997 \r If the JAVA package appears in the list you must uninstall it
998 first by issuing the command
\r
999 Octave > pkg uninstall java
\r
1001 \r Now the java package should not be listed anymore. If you have
1002 used the JAVA package during the current session of Octave, you have to
1003 exit and restart Octave before you can uninstall the package. This is
1004 because the system keeps certain libraries in memory after they have
1005 been loaded once.
\r \r
1007 4.5.2 Make sure that the build environment is configured properly
1008 -----------------------------------------------------------------
1010 The installation process requires that the environment variable
1011 `JAVA_HOME' points to the Java Development Kit (JDK) on your computer.
1013 * Note that JDK is not equal to JRE (Java Runtime Environment). The
1014 JDK home directory contains subdirectories with include, library
1015 and executable files which are required to compile the JAVA
1016 package. These files are not part of the JRE, so you definitely
1019 * Do not use backslashes but ordinary slashes in the path.
\r
1020 \r Set the environment variable `JAVA_HOME' according to your local
1021 JDK installation. Please adapt the path in the following examples
1022 according to the JDK installation on your system.
1023 \r If you are using a Windows system that might be:
\r
1024 Octave > setenv("JAVA_HOME","C:/Java/jdk1.6.0_21");
\r
1025 Note, that on both system types, Windows as well as Linux, you must
1026 use the forward slash '/' as the separator, not the backslash '\'.
\r \r
1027 If you are using a Linux system this would look probably more like:
\r
1028 Octave > setenv("JAVA_HOME","/usr/local/jdk1.6.0_21");
\r
1031 4.5.3 Compile and install the package in Octave
1032 -----------------------------------------------
1034 If you have for example saved the package archive on your Z: drive the
1035 command would be:
\r
1036 Octave> pkg install -verbose z:/java-1.2.8.tar.gz
\r
1037 or if you have Linux and the package file is stored in your home
1039 Octave > pkg install -verbose ~/java-1.2.8.tar.gz
\r
1040 The option `-verbose' will produce some lengthy output, which should
1041 not show any errors
\r (maybe a few warnings at best).
\r \r You can
1042 then produce a list of all installed packages:
\r
1044 \r This list of packages should now include the package JAVA:
\r
1046 Package Name | Version | Installation directory
\r
1047 --------------+---------+-----------------------
\r
1048 java *| 1.2.8 | /home/octavio/octave/java-1.2.8
\r
1052 4.5.4 Test the java package installation
1053 ----------------------------------------
1055 \r The following code creates a Java string object, which however is
1056 automatically converted to an Octave string:
\r
1057 Octave > s = javaObject('java.lang.String', 'Hello OctaveString')
\r
1058 s = Hello OctaveString
\r
1059 \r Note that the java package automatically transforms the Java
1060 String object to an Octave string. This means that you cannot apply
1061 Java String methods to the result.
\r \r This "auto boxing" scheme
1062 seems to be implemented for the following Java classes:
\r
1063 * java.lang.Integer
\r
1065 * java.lang.Double
\r
1067 * java.lang.Boolean
\r
1069 * java.lang.String
\r
1070 \r If you instead create an object for which no "auto-boxing" is
1071 implemented, `javaObject' returns the genuine Java object:
\r
1072 Octave > v = javaObject('java.util.Vector')
\r
1074 <Java object: java.util.Vector>
\r
1075 Octave > v.add(12);
\r
1076 Octave > v.get(0)
\r
1078 \r If you have created such a Java object, you can apply all methods
1079 of the Java class to the returned object. Note also that for some
1080 objects you must specify an initializer:
\r
1082 Octave > d = javaObject('java.lang.Double')
\r
1083 error: [java] java.lang.NoSuchMethodException: java.lang.Double
\r
1085 Octave > d = javaObject('java.lang.Double',12.34)
\r
1090 File: octave-java.info, Node: Which TeX symbols are implemented in the dialog functions?, Prev: How to compile the java package in Octave?, Up: Top
1092 4.6 Which TeX symbols are implemented in the dialog functions?
1093 ==============================================================
1095 \r The dialog functions contain a translation table for TeX like symbol
1096 codes. Thus messages and labels can be tailored to show some common
1097 mathematical symbols or Greek characters. No further TeX formatting
1098 codes are supported. The characters are translated to their Unicode
1099 equivalent. However, not all characters may be displayable on your
1100 system. This depends on the font used by the Java system on your
1101 computer.
\r \r Each TeX symbol code must be terminated by a space
1102 character to make it distinguishable from the surrounding text.
1103 Therefore the string `\alpha =12.0' will produce the desired result,
1104 whereas `\alpha=12.0' would produce the literal text '\ALPHA=12.0'.
\r \r
1106 *See also:* *note errordlg: doc-errordlg,
\r *note helpdlg:
1107 doc-helpdlg,
\r *note inputdlg: doc-inputdlg,
\r *note
1108 listdlg: doc-listdlg,
\r *note msgbox: doc-msgbox,
\r
1109 *note questdlg: doc-questdlg,
\r *note warndlg: doc-warndlg.
\r
1120 * array, creating a Java array: javaArray. (line 6)
1121 * available functions: Top. (line 29)
1122 * calling Java from Octave: Top. (line 6)
1123 * calling Octave from Java: Top. (line 16)
1124 * classes, making available to Octave: How to make Java classes available?.
1126 * classpath, adding new path: javaaddpath. (line 6)
1127 * classpath, difference between static and dynamic: How to make Java classes available?.
1129 * classpath, displaying: javaclasspath. (line 8)
1130 * classpath, dynamic <1>: javaaddpath. (line 6)
1131 * classpath, dynamic: javaclasspath. (line 8)
1132 * classpath, removing path: javarmpath. (line 6)
1133 * classpath, setting: How to make Java classes available?.
1135 * classpath, static: javaclasspath. (line 8)
1136 * classpath.txt: How to make Java classes available?.
1138 * compiling the java package, how?: How to compile the java package in Octave?.
1140 * dialog, displaying a help dialog: helpdlg. (line 6)
1141 * dialog, displaying a list dialog: listdlg. (line 6)
1142 * dialog, displaying a question dialog: questdlg. (line 6)
1143 * dialog, displaying a warning dialog <1>: warndlg. (line 6)
1144 * dialog, displaying a warning dialog: msgbox. (line 6)
1145 * dialog, displaying an error dialog: errordlg. (line 6)
1146 * dialog, displaying an input dialog: inputdlg. (line 6)
1147 * dynamic classpath <1>: How to make Java classes available?.
1149 * dynamic classpath: javaclasspath. (line 8)
1150 * dynamic classpath, adding new path: javaaddpath. (line 6)
1151 * field, returning value of Java object field: java_get. (line 6)
1152 * field, setting value of Java object field: java_set. (line 6)
1153 * fields, displaying available fields of a Java object: javafields.
1155 * functions, available in the package java: Top. (line 29)
1156 * instance, how to create: How to create an instance of a Java class?.
1158 * java package, how to compile?: How to compile the java package in Octave?.
1160 * java package, how to install?: How to compile the java package in Octave?.
1162 * java package, how to uninstall?: How to compile the java package in Octave?.
1164 * Java, calling from Octave: Top. (line 6)
1165 * Java, using with Octave: Top. (line 6)
1166 * memory, displaying Java memory status: javamem. (line 6)
1167 * memory, limitations: How can I handle memory limitations?.
1169 * method, invoking a method of a Java object <1>: java_invoke. (line 6)
1170 * method, invoking a method of a Java object: javaMethod. (line 6)
1171 * methods, displaying available methods of a Java object: javamethods.
1173 * object, creating a Java object <1>: java_new. (line 6)
1174 * object, creating a Java object: javaObject. (line 6)
1175 * object, how to create: How to create an instance of a Java class?.
1177 * Octave and Matlab, how to distinguish between: How to distinguish between Octave and Matlab?.
1179 * Octave, calling from Java: Top. (line 16)
1180 * package java, available functions: Top. (line 29)
1181 * package, how to compile?: How to compile the java package in Octave?.
1183 * path, adding to classpath: javaaddpath. (line 6)
1184 * path, removing from classpath: javarmpath. (line 6)
1185 * static classpath <1>: How to make Java classes available?.
1187 * static classpath: javaclasspath. (line 8)
1188 * symbols, translation table: Which TeX symbols are implemented in the dialog functions?.
1190 * TeX symbols, translation table: Which TeX symbols are implemented in the dialog functions?.
1192 * translation table for TeX symbols: Which TeX symbols are implemented in the dialog functions?.
1194 * using Octave with Java: Top. (line 6)
1202 Node: javaclasspath
\7f2609
1203 Ref: doc-javaclasspath
\7f2739
1204 Node: javaaddpath
\7f4789
1205 Ref: doc-javaaddpath
\7f4919
1206 Node: javarmpath
\7f5818
1207 Ref: doc-javarmpath
\7f5940
1208 Node: javamem
\7f6642
1209 Ref: doc-javamem
\7f6756
1210 Node: javaArray
\7f9286
1211 Ref: doc-javaArray
\7f9404
1212 Node: javaObject
\7f10242
1213 Ref: doc-javaObject
\7f10363
1214 Node: java_new
\7f11628
1215 Ref: doc-java_new
\7f11746
1216 Node: javaMethod
\7f12376
1217 Ref: doc-javaMethod
\7f12499
1218 Node: java_invoke
\7f13225
1219 Ref: doc-java_invoke
\7f13350
1220 Node: java_get
\7f14123
1221 Ref: doc-java_get
\7f14242
1222 Node: java_set
\7f14859
1223 Ref: doc-java_set
\7f14978
1224 Node: javamethods
\7f15629
1225 Ref: doc-javamethods
\7f15756
1226 Node: javafields
\7f16975
1227 Ref: doc-javafields
\7f17098
1228 Node: msgbox
\7f18392
1229 Ref: doc-msgbox
\7f18504
1230 Node: errordlg
\7f19854
1231 Ref: doc-errordlg
\7f19967
1232 Node: helpdlg
\7f20771
1233 Ref: doc-helpdlg
\7f20884
1234 Node: inputdlg
\7f22115
1235 Ref: doc-inputdlg
\7f22229
1236 Node: listdlg
\7f24956
1237 Ref: doc-listdlg
\7f25069
1238 Node: questdlg
\7f27274
1239 Ref: doc-questdlg
\7f27388
1240 Node: warndlg
\7f28988
1241 Ref: doc-warndlg
\7f29138
1242 Node: How to distinguish between Octave and Matlab?
\7f30751
1243 Ref: doc-FAQ
\7f31002
1244 Node: How to make Java classes available?
\7f31650
1245 Node: How to create an instance of a Java class?
\7f35404
1246 Node: How can I handle memory limitations?
\7f36140
1247 Node: How to compile the java package in Octave?
\7f39263
1248 Node: Which TeX symbols are implemented in the dialog functions?
\7f44056