comparison doc/interpreter/java.txi @ 16359:253e13e77d12

doc: java.texi: dropped OF package specific text
author Philip Nienhuis <prnienhuis@users.sf.net>
date Sat, 23 Mar 2013 00:09:25 +0100
parents 01d4f742d75d
children 1834b91292ab
comparison
equal deleted inserted replaced
16358:0db0926c2d0f 16359:253e13e77d12
143 @menu 143 @menu
144 * How to distinguish between Octave and Matlab?:: 144 * How to distinguish between Octave and Matlab?::
145 * How to make Java classes available?:: 145 * How to make Java classes available?::
146 * How to create an instance of a Java class?:: 146 * How to create an instance of a Java class?::
147 * How can I handle memory limitations?:: 147 * How can I handle memory limitations?::
148 * How to compile the java package in Octave?::
149 * Which @TeX{} symbols are implemented in the dialog functions?:: 148 * Which @TeX{} symbols are implemented in the dialog functions?::
150 @end menu 149 @end menu
151 150
152 @c ------------------------------------------------------------------------ 151 @c ------------------------------------------------------------------------
153 @node How to distinguish between Octave and Matlab? 152 @node How to distinguish between Octave and Matlab?
208 classpath}. Classes appearing in the @var{static} as well as in the 207 classpath}. Classes appearing in the @var{static} as well as in the
209 @var{dynamic classpath} will therefore be found in the @var{static classpath} 208 @var{dynamic classpath} will therefore be found in the @var{static classpath}
210 and loaded from this location. Classes which shall be used regularly or must 209 and loaded from this location. Classes which shall be used regularly or must
211 be available to all users should be added to the @var{static classpath}. The 210 be available to all users should be added to the @var{static classpath}. The
212 @var{static classpath} is populated once from the contents of a plain text file 211 @var{static classpath} is populated once from the contents of a plain text file
213 named @file{classpath.txt} when the Java Virtual Machine starts. This file 212 named @file{classpath.txt} or @file{javaclasspath.txt} when the Java Virtual
214 contains one line for each individual classpath to be added to the @var{static 213 Machine starts. This file contains one line for each individual classpath to be
215 classpath}. These lines can identify single class files, directories containing 214 added to the @var{static classpath}. These lines can identify single class
216 class files or Java archives with complete class file hierarchies. Comment 215 files, directories containing class files or Java archives with complete class
217 lines starting with a @code{#} or a @code{%} character are ignored. 216 file hierarchies. Comment lines starting with a @code{#} or a @code{%}
218 217 character are ignored.
219 The search rules for the file @file{classpath.txt} are: 218
219 The search rules for the file @file{classpath.txt} (or @file{javaclasspath.txt})
220 are:
220 221
221 @itemize 222 @itemize
222 @item First, Octave searches for the file @file{classpath.txt} in your home directory, 223 @item First, Octave tries to locate it in the current directory (where Octave
223 If such a file is found, it is read and defines the initial @var{static 224 was started from). If such a file is found, it is read and defines the initial
224 classpath}. Thus it is possible to build an initial static classpath on a 'per 225 @var{static classpath}. So it is possible to define a static classpath on a 'per
225 user' basis. 226 Octave invocation' basis.
226 227
227 @item Next, Octave looks for another file @file{classpath.txt} in the package 228 @item Next, Octave searches in the user's home directory. If a file
228 installation directory. This is where @file{javaclasspath.m} resides, usually 229 @file{classpath.txt} (or @file{javaclasspath.txt}) exists here, its contents
229 something like @file{@dots{}\share\Octave\packages\java-1.2.8}. You can find 230 are appended to the static classpath (if any). Thus it is possible to build an
230 this directory by executing the command 231 initial static classpath on a 'per user' basis.
231 232
232 @example 233 @item Finally, Octave looks for a next occurrence of file @file{classpath.txt}
233 pkg list 234 (@file{javaclasspath.txt}) in the m-files directory where Octave Java functions
234 @end example 235 live. This is where @file{javaclasspath.m} resides, usually something like
235 236 @file{@dots{}/share/octave/packages/<version>/m/java}. You can find this
236 If this file exists, its contents is also appended to the static classpath. 237 directory by executing the command
237 Note that the archives and class directories defined in this file will affect 238
239 @example
240 which javaclasspath
241 @end example
242
243 If this file exists here, its contents are also appended to the static classpath.
244 Note that the archives and class directories defined in this last step will affect
238 all users. 245 all users.
239 @end itemize 246 @end itemize
240 247
241 Classes which are used only by a specific script should be placed in the 248 Classes which are used only by a specific script should be placed in the
242 @var{dynamic classpath}. This portion of the classpath can be modified at 249 @var{dynamic classpath}. This portion of the classpath can be modified at
389 ans = 12.34 396 ans = 12.34
390 @end group 397 @end group
391 @end example 398 @end example
392 399
393 @seealso{javamem} 400 @seealso{javamem}
394
395 @c ------------------------------------------------------------------------
396 @node How to compile the java package in Octave?
397 @subsection How to compile the java package in Octave?
398 @c - index -
399 @cindex package, how to compile?
400 @cindex compiling the java package, how?
401 @cindex java package, how to compile?
402 @cindex java package, how to install?
403 @cindex java package, how to uninstall?
404 @c - index -
405
406 Most Octave installations come with the @var{java} package pre-installed. In
407 case you want to replace this package with a more recent version, you must
408 perform the following steps:
409
410 @c ---------
411 @menu
412 * Uninstall the currently installed package @var{java}::
413 * Make sure that the build environment is configured properly::
414 * Compile and install the package in Octave::
415 * Test the java package installation::
416 @end menu
417
418 @node Uninstall the currently installed package @var{java}
419 @subsubsection Uninstall the currently installed package @var{java}
420 Check whether the @var{java} package is already installed by issuing
421 the @code{pkg list} command:
422
423 @example
424 @group
425 octave> pkg list
426 Package Name | Version | Installation directory
427 --------------+---------+-----------------------
428 java *| 1.2.8 | /home/octavio/octave/java-1.2.8
429 octave>
430 @end group
431 @end example
432
433 @noindent
434 If the @var{java} package appears in the list you must uninstall it first by
435 issuing the command
436
437 @example
438 @group
439 octave> pkg uninstall java
440 octave> pkg list
441 @end group
442 @end example
443
444 Now the java package should not be listed anymore. If you have used the
445 @var{java} package during the current session of Octave, you have to exit and
446 restart Octave before you can uninstall the package. This is because the
447 system keeps certain libraries in memory after they have been loaded once.
448
449 @c ---------
450 @node Make sure that the build environment is configured properly
451 @subsubsection Make sure that the build environment is configured properly
452 The installation process requires that the environment variable
453 @w{@env{JAVA_HOME}} points to the Java Development Kit (JDK) on your computer.
454
455 @itemize @bullet
456 @item
457 Note that JDK is not equal to JRE (Java Runtime Environment). The JDK home
458 directory contains subdirectories with include, library and executable files
459 which are required to compile the @var{java} package. These files are not part
460 of the JRE, so you definitely need the JDK.
461
462 @item
463 Do not use backslashes but ordinary slashes in the path.
464 @end itemize
465
466 Set the environment variable @w{@env{JAVA_HOME}} according to your local JDK
467 installation. Please adapt the path in the following examples according to the
468 JDK installation on your system. If you are using a Windows system that might
469 be:
470
471 @example
472 octave> setenv("JAVA_HOME","C:/Java/jdk1.6.0_21");
473 @end example
474
475 Note, that on both system types, Windows as well as Linux, you must use the
476 forward slash '/' as the separator, not the backslash '\'.
477
478 If you are using a Linux system this would look probably more like:
479
480 @example
481 octave> setenv("JAVA_HOME","/usr/local/jdk1.6.0_21");
482 @end example
483
484 @c ---------
485 @node Compile and install the package in Octave
486 @subsubsection Compile and install the package in Octave
487 If you have for example saved the package archive on your @file{z:} drive the
488 command would be:
489
490 @example
491 Octave> pkg install -verbose z:/java-1.2.8.tar.gz
492 @end example
493
494 @noindent
495 or if you have Linux and the package file is stored in your home directory:
496
497 @example
498 octave> pkg install -verbose ~/java-1.2.8.tar.gz
499 @end example
500
501 The option @option{-verbose} will produce some lengthy output, which should not
502 show any errors (maybe a few warnings at best).
503
504 You can then produce a list of all installed packages:
505
506 @example
507 octave> pkg list
508 @end example
509
510 This list of packages should now include the package @var{java}:
511
512 @example
513 @group
514 octave> pkg list
515 Package Name | Version | Installation directory
516 --------------+---------+-----------------------
517 java *| 1.2.8 | /home/octavio/octave/java-1.2.8
518 octave>
519 @end group
520 @end example
521
522 @c ---------
523 @node Test the java package installation
524 @subsubsection Test the java package installation
525
526 The following code creates a Java string object, which however is automatically
527 converted to an Octave string:
528
529 @example
530 @group
531 octave> s = javaObject('java.lang.String', 'Hello OctaveString')
532 s = Hello OctaveString
533 @end group
534 @end example
535
536 Note that the java package automatically transforms the Java String object to
537 an Octave string. This means that you cannot apply Java String methods to the
538 result.
539
540 This "auto boxing" scheme seems to be implemented for the following Java
541 classes:
542
543 @itemize @bullet
544 @item
545 java.lang.Integer
546
547 @item
548 java.lang.Double
549
550 @item
551 java.lang.Boolean
552
553 @item
554 java.lang.String
555 @end itemize
556
557 If you instead create an object for which no "auto-boxing" is implemented,
558 @code{javaObject} returns the genuine Java object:
559
560 @example
561 @group
562 octave> v = javaObject('java.util.Vector')
563 v =
564 <Java object: java.util.Vector>
565 octave> v.add(12);
566 octave> v.get(0)
567 ans = 12
568 @end group
569 @end example
570
571 If you have created such a Java object, you can apply all methods of the Java
572 class to the returned object. Note also that for some objects you must specify
573 an initializer:
574
575 @example
576 @group
577 % not:
578 octave> d = javaObject('java.lang.Double')
579 error: [java] java.lang.NoSuchMethodException: java.lang.Double
580 % but:
581 octave> d = javaObject('java.lang.Double',12.34)
582 d = 12.340
583 @end group
584 @end example
585 401
586 @c ------------------------------------------------------------------------ 402 @c ------------------------------------------------------------------------
587 @node Which @TeX{} symbols are implemented in the dialog functions? 403 @node Which @TeX{} symbols are implemented in the dialog functions?
588 @subsection Which @TeX{} symbols are implemented in the dialog functions? 404 @subsection Which @TeX{} symbols are implemented in the dialog functions?
589 @c - index - 405 @c - index -