Java Use on KCCF Unix System

 

Steps for using Java


(1) Create Java source code using editor (any editor, e.g., CDE screen editor or vi/emacs)
    -save source code after editing (use .java extension)

(2) Compile Java source code from a terminal window

    javac source_code_name.java

(3) Correct any compiler errors using the editor, then repeat compiler step (2)

(4) Run code from a unix terminal window using

    java  source_code_name
 
 
 

Java Language-related APL Unix Commands

...(see man pages for details)

 
appletviewer Java applet viewer
jar Java archive tool
java Java interpreter
javac  Java compiler
javadoc Java API Documentation Generator 
javakey Java security tool
javald wrapper creator for java application
javap Java class file disassembler
jdb Java debugger
jre Java runtime interpreter
native2ascii native to ASCII converter
rmic Java RMI stub compiler 
rmiregistry Java remote object registry
serialver serial version command

===========================================================================

NAME
     javac - Java compiler

SYNOPSIS
     javac [ -classpath path ] [ -d directory ] [ -depend ]
          [ -deprecation ] [ -encoding encoding_name ]
          [ -g ] [ -Jjavaoption ] [ -nowarn ] [ -O ]
          [ -verbose ] filename.java ...

     javac_g [ -classpath path ] [ -d directory ] [ -depend ]
          [ -deprecation ] [ -encoding encoding_name ]
          [ -g ] [ -Jjavaoption ] [ -nowarn ] [ -O ]
          [ -verbose ] filename.java ...

DESCRIPTION
     The javac  command  compiles  Java  source  code  into  Java
     bytecodes  that  can then be used by the java(1) interpreter
     to interpret the Java bytecodes.

     Java source code must be contained in files which  filenames
     thatend with the .java extension. The file name must be con-
     structed from the class  name,  as  classname.java,  if  the
     class is public or is referenced from another source file.

     For every class defined in  each  source  file  compiled  by
     javac,  the  compiler  stores  the  resulting bytecodes in a
     class file with a name of the form  classname.class.  Unless
     you  specify  the  -d option, the compiler places each class
     file in the same directory as the corresponding source file.

     When the compiler must refer to your own classes,  you  need
     to  specify  their  location.  Use  the -classpath option or
     CLASSPATH environment variable to do this. The class path is
     a sequence of directories (or zip files) that javac searches
     for classes not already defined in any of the  files  speci-
     fied  directly  as  command arguments. The compiler looks in
     the class path for both a source  file  and  a  class  file,
     recompiling  the source (and regenerating the class file) if
     it is newer.

     Set the property javac.pipe.output to true  to  send  output
     messages  to  System.out.   Set  javac.pipe.output to FALSE,
     that  is,  do  not  set  it,  to  send  output  messages  to
     System.err.

     javac_g is a non-optimized version of javac suitable for use
     with  debuggers  like  jdb(1)  for  debugging  javac itself.
     Using javac_g is not equivalent to using the  command  javac
     -g.

OPTIONS
     -classpath path

                    Specifies the path  javac  uses  to  look  up
                    classes  needed to run javac or being records
                    by other  classes  you  are  compiling.   the
                    default or the CLASSPATH environment variable
                    if it is set. Directories  are  separated  by
                    colons.  It is often useful for the directory
                    containing the source  files  to  be  on  the
                    class  path.  You  should  always include the
                    system classes at the end of  the  path.  For
                    example:

                         example%        javac         -classpath
                         .:/home/avh/classes:/usr/local/java/classes
                         ...
 

     -d directory   Specifies the root  directory  of  the  class
                    file  hierarchy.  In  other  words,  this  is
                    essentially a destination directory for  your
                    compiled classes.  For example, doing:

                         example%  javac   -d   /home/avh/classes
                         MyProgram.java

                    causes  the  compiled  class  files  for  the
                    classes  in the MyProgram.java source file to
                    be      saved      in      the      directory
                    /home/avh/classes/demos/awt.  If your classes
                    are defined in  the  package  demos/awt,  the
                    class  files would be placed in the directory
                    /home/avh/classes/demos/awt.

                    Please  note  that  the  -d  and   -classpath
                    options  have  independent  effects. The com-
                    piler reads only from  the  class  path,  and
                    writes  only to the destination directory. It
                    is often useful for the destination directory
                    to  be on the class path. If the -d option is
                    not specified, the  source  files  should  be
                    stored in a directory hierarchy that reflects
                    the package structure, so that the  resulting
                    class files can be easily located.

     -depend        This  option  makes  the  compiler   consider
                    recompiling  class  files that are referenced
                    from other class  files.  Normally,  it  only
                    recompiles missing or out-of-date class files
                    that are referred to from source code.

     -deprecation   Generate a warning for every use or  override
                    of a deprecated member or class.  A member or
                    class  is  deprecated  if  its  documentation
                    comment  contains  the  @deprecated tag.  The
                    compiler will emit a morning at  the  end  of
                    compilation  whether  or  not -deprecation is
                    used; this option causes the location of each
                    individual use or override to be noted.

                    Deprecated  members  or  classes  are   deli-
                    berately  not  mentioned  if  the source file
                    containing the deprecation  is  being  recom-
                    piled.   This  can happen because the file is
                    on the command line  or  because  -depend  is
                    used and the source file was out of date.

     -encoding encoding_name
                    Specify the source file encoding  name,  such
                    as EUCJIS/SJIS.  If this option is not speci-
                    fied, then the platform default converter  is
                    used.

     -g             Enables  generation  of   debugging   tables.
                    Debugging  tables  contain  information about
                    line numbers and local variables  -  informa-
                    tion   used   by  Java  debugging  tools.  By
                    default, only  line  numbers  are  generated,
                    unless optimization (-O) is turned on.

     -Jjavaoption   Passes through the  string  javaoption  as  a
                    single  argument  to  the java(1) interpreter
                    that runs the compiler. The  argument  should
                    not  contain  spaces. Multiple argument words
                    must all begin with the prefix -J,  which  is
                    stripped.  This  is  useful for adjusting the
                    compiler's execution  environment  or  memory
                    usage.

     -nowarn        Turns off warnings.  If  used,  the  compiler
                    does not print out any warnings.

     -O             Directs the compiler to try to generate  fas-
                    ter   code  by  inlining  static,  final  and
                    private methods. This option  may  slow  down
                    compilation,  make larger class files, and/or
                    make it difficult  to  debug.  -O  implicitly
                    turns on -depend and turns off -g.

                    This option informs  the  compiler  that  all
                    generated  class  files  are guaranteed to be
                    delivered and upgraded as  a  unit,  enabling
                    optimizations that may otherwise break binary
                    compatibility. Use this option  with  discre-
                    tion.
 

                    The  Java  Language   Specification   section
                    13.4.21  describes  situations in which it is
                    legal  to  use  a  java  compiler  to  inline
                    methods. The compiler will only optimize code
                    for source which is available during the com-
                    pilation,  so  the only .java files discover-
                    able by the compiler should  be  for  classes
                    intended  to  be  delivered  or upgraded as a
                    unit. In particular, ensure that  no  sources
                    for   other   classes   are   accessible   on
                    CLASSPATH, keeping in mind that  the  present
                    working   directory,   `.',  is  appended  to
                    CLASSPATH.

                    To ensure that a product is able  to  run  on
                    1.1  as well as future binary-compatible java
                    virtual machines, one must  ensure  that  any
                    sources  for JDK 1.1 classes are never avail-
                    able along CLASSPATH while using -O.

     -verbose       Causes the compiler and linker to  print  out
                    messages  about  what  source files are being
                    compiled  and  what  class  files  are  being
                    loaded.

EXAMPLE
  Compiling One or More Classes
     In  this  example,  the  source   files   are   located   at
     /home/ws/src/java/awt/*.java.

          % cd /home/ws/src/java/awt/
          % javac Button.java Canvas.java

     Compiles the two classes.

ENVIRONMENT VARIABLES
     CLASSPATH      Used to provide the system  with  a  path  to
                    user-defined    classes.    Directories   are
                    separated by colons, for example,

                         .:/home/avh/classes:/usr/local/java/classes

ATTRIBUTES
     See attributes(5) for a description of the following  attri-
     butes:

     __________________________________
    | ATTRIBUTE TYPE|  ATTRIBUTE VALUE|
    |_______________|_________________|
    | Availability  |  SUNWjvdev      |
    |_______________|_________________|
 
 
 

SunOS 5.6           Last change: 8 June 1997                    4
 
 
 

SEE ALSO
     java(1),  javadoc(1),  javah(1),  javap(1),  jdb(1),  attri-
     butes(5)
 
 

===========================================================================

NAME
     java - Java interpreter

SYNOPSIS
     java  [ options ] classname [ args ]

DESCRIPTION
     java implements the Java  Virtual  Machine  that  interprets
     Java  bytecodes.   The  classname  argument is the name of a
     Java class which contains the main() method of a Java appli-
     cation.   classname must be fully qualified by including the
     package name.

     Any arguments that appear after  classname  on  the  command
     line are passed to the Java application.

OPTIONS
     java supports the following options:

     -classpath path
          path is a colon separated list of  directories  or  ZIP
          files  where  java  should search for Java class files.
          For example:

          /home/myclasses.zip:/usr/lib/classlib:NCDCLASSES

          The special string, NCDCLASSES, can be used anywhere in
          the class path.  It's a special name recognized by java
          and represents the set of base class files  shipped  by
          NCD.   It  saves the user from having to know where the
          base class files have been actually installed.

     -mxsize
          This option sets the size of the memory heap that  java
          will  use  for allocating objects.  The heap is garbage
          collected so that Java  applications  do  not  have  to
          explicitly free memory when they are finished with it.

          The NCD network computer must have size bytes  of  free
          contiguous  memory  or  java will not be able to start.
          By default, java will allocate 3 MB for the heap.  size
          must be at least 50 KB.

          You can specify the size of the heap  in  kilobytes  or
          megabytes by appending the letter k or m, respectively,
          to the size.  For example, -mx5m specifies a heap of  5
          MB.

     -noasyncgc
          By default, garbage collection is done by a low  prior-
          ity  thread that will run when the application is idle.
          This option disables this garbage collector  thread  so
          that  garbage  collection  will  only  take  place when
          explicitly requested or when the application  runs  out
          of heap space.

     -ssstacksize
          This option can be used to set the size of the stack to
          be  used  by Java threads.  As with the -mx option, you
          can specify the stack size in kilobytes or megabytes by
          appending  a  k  or m, respectively.  The minimum stack
          size is 32 KB and the maximum is currently 512 KB.

          This option shouldn't normally be needed.

     -ossjavaStacksize
          Each Java thread requires two stacks.  The second stack
          is  needed by the Java Virtual Machine to interpret the
          bytecodes.  This option can be used to set the size  of
          the  Java stack to be used.  As with the other options,
          you can specify the stack size in  kilobytes  or  mega-
          bytes.

          This option shouldn't normally be needed.

     -v   Runs java in verbose mode.  Messages will  be  sent  to
          the diagnostic log as class files are loaded.

     -verify
          Runs the bytecode verifier on all class files that  are
          loaded.

     -verifyremote
          Runs the bytecode verifier only for  class  files  that
          are loaded via a classloader.  This is the default.

     -noverify
          Turns off the bytecode verifier.

     -verbosegc
          Causes a message to be sent to the diagnostic log when-
          ever the garbage collector is invoked.

     -DpropertyName=propertyValue
          This option allows the user to set Java properties from
          the  command  line.  You can specify any number of pro-
          perties on the command line.  For example:

          -Duser.home=/usr/home -Duser.dir=/usr/tmp

          sets the user's home directory  to  /usr/home  and  the
          current working directory to /usr/tmp.