Amadeus_AlgJava: TUTORIAL

Introduction
A brief introduction to AlgJava
Programming environment
Macros

Program Structure
Editing
Using screen graphics
Using konsole dialogue
 Using text files
Debugging tools
Groups and comments

Advanced topics
Import and static variables declarations
Labeled control statements
System properties
Migration between operating systems
Action descriptions in project
Images

Java Application Programming Interface (API)
Class Math: method summary
Class String: method summary
Class Integer: method summary
Class Double: method summary
Class Graphics: method summary







Introduction

The system Amadeus_AlgJava enables the user to quickly develop  and experiment with simple Java-based programs, in order to master algorithmic  programming techniques and concepts.  The corresponding programming language AlgJava makes use of all Java primitives, and the user can use a lot of methods from the Java standard API (incl. all tools from the package java.lang). However, the possibility to develop multi-class program systems  is eliminated. So, complexities of defining classes are hidden from the user.
Several simplifications are offered, e.g. predefined frame for screen graphics,  the console input
method readln() as the  analogue-antipode  of [System.out.]println(...)et al. For the purpose of debugging, the user may insert break points together with special inspection statements, which allow inspection of the current values of  given expressions and arrays.  

All demo-programs delivered together with Amadeus_AlgJava  belong to the project AlgJavaDemo.


A brief introduction to AlgJava

Elementary statements (ending with a semicolon) are seen as primitives of the AlgJava language.

All primitives are written in Java, except the following simplifications:

  instead of                        System.out.println(…  and  System.out.print(…
  one may write                  println(…             and print(…

  instead of the loop head         for(int i = a; i <= b; i++)
 
one may write                         i = a .. b  (at least 2 sequential dots).

Actually, any program in AlgJava is considered a Java main class with the name Main. However, anything related to user-defined classes is hidden from AlgJava programmers.
The main method (public static void main (String[] args)… )
is also hidden. The first part of an AlgJava program (after import and static variables declarations) until the first method declaration or  the end of program  constitute the content of the main method.
All method declarations represent static methods and are located in the second part of the program. No modifiers
(public static …) are needed in method declarations. The modifier static is added automatically before compiling.

Programming of screen graphics is supported by a simple mouse-sensitive frame. Its instance (named raam.) is created behind the scene, i.e. hidden from the users.

Programming of  console dialogue  is supported by a special method  readln for console input.

The readers and writers for text files can be declared in a simple manner.

For debugging  purposes, break points can be included into AlgJava programs.



Programming environment

The programming environment has been derived from the system Amadeus. In this system, instead of  plain texts, more structured texts called  skm-texts (sketchy modeled texts) are handled. The main construction unit in skm-texts is a sketch. A sketch consists of one ore more branches. Every branch contains as its members primitives  (primitive members) and (sub)sketches. A primitive is written as a plain text in one or more lines. Any sketch as well as branch can have head, represented by a primitive.

A sample structure of a sketch, containing two branches:

- Start of sketch
   [SKETCH HEAD -- primitive]
   - Branch (1)
      [BRANCH HEAD
-- primitive]
          MEMBER -- primitive or sub-sketch
          MEMBER -- primitive or sub-sketch
             ...

   - Branch (2)
     [BRANCH HEAD
-- primitive]
          MEMBER -- primitive or sub-sketch
          MEMBER -- primitive or sub-sketch
             ...

- End of sketch

Comments can be added to any sketch, branch and primitive text. A comment is a one-line  plain text (and is displayed green on the screen).  The sketch comment is written at the beginning of the sketch (and is automatically displayed also at the end of the sketch). The branch comment is written at the beginning of the branch. The comment of primitive text is located after the last line of the text.
An empty plain text is represented on the screen by a special symbol
» denoting the start of the possible further fill-in.

The programmer works mainly in two windows. One of them is the project window, displaying the current project, the other is for the current AlgJava program. When the last is run,  additionally a  console window and,  in the case of  a graphics-oriented program, a graphic window appear. 

An AlgJava project is also an skm-text and consists of two branches.
The first branch contains three sections (sub-sketches):
The system Amadeus_AlgJava contains two predefined projects in the files AlgJavaDemo.html and AlgJavaWorks.html in  the folder .\Portfolio. The first branches of these projects differ only in the definition of the program folder name (Kaust) in the section Paths:
Kaust: .\demo
Kaust: .\workspace

If the programmer uses only these two projects, for instance, investigates demo-programs in the folder .\demo and creates her/his new programs in the folder .\workspace then there is no need to consider/edit the first branch of any of these projects. It may be kept in the iconified (folded) form. 
The second branch of a project contains the list of AlgJava program names, belonging to that project.  The list is edited by the programmer, in accord to the dynamics of the set of programs in the project. In particular, if a program has become  superfluous, then its name should be removed from the list of names (by editing the second branch of the project) and its file must be removed (using the operating system tools) from the programs folder, usually the folder  .\workspace.

There are two possibilities to open a program:
  1. Triple left mouse-click on a program name in the project window creates a new program window and loads the  program into it. 
  2. The menu command File>Open in the program window loads into the program window the program whose name has been (preliminarily) selected in the project window .
In the project window,  the name of the opened program is grayed.
If the file of the program to be opened is missing in the programs folder, then an empty program is loaded into the program window.

To start composing a new program,  the new name should be inserted into the project and the program opened as described above.

The program name must not conatin any spaces and must be followed with type (.algjava).
The modified project should be  saved (File>Export in the project window) immediately after its modification.

Processing of an AlgJava program displayed in the program window is initialized by the menu command File>Save (or Ctrl+s). It invokes the sequence of operations, described in the Save-script section of the current project. In the case of standard projects
(AlgJavaDemo and AlgJavaWorks) the following operations will be performed:
Suppose, the name of the current
AlgJava program is Hello.algjava.  Then File>Save (or Ctrl+s) leads to
Compiler error messages are displayed in a separate window. The first error is also localized on the level of the AlgJava source. The defective primitive in the program is indicated by a small red square in front of the primitive text.

If the program consumes command line arguments, these must be previously written at the end of the last line of  the Save-script section in the current project.

In order to observe  the corresponding Java program one should  select all of the AlgJava program, thereafter apply Tools>Textualize. The resulting Java-text (with numbered lines) is displayed in a separate window.
Also, only a part of an AlgJava program can be translated and observed:
enclose the part (
Editor>Enclose or Ctrl+E) into a separate group, thereafter  apply Tools>Textualize.

In order to save the current program as another file, the menu command in the program window  
File>Export
is used.

NB! The offered type of the new file is html, not algjava.
NB! The current program in the program window is not touched: neither its name nor connection to the related file does not change.

Closing (×) the program window closes the program.  




Macros

The system Amadeus_AlgJava offers (initially) three sets of macros located in the folder macros (as files of type html).
In general, at the start
macros from these sets are activated, whose names are listed in the system properties file Amadeus.properties.
By default,  the listing contains the sets
AltGrMacro.htmlAlgJavaMacro.html and Kirillitsa.html.
Activated macros can be seen in the LOG window
(initially located behind the project window).

Note.
If the properties file Amadeus.properties defines
   locale = RUS
or
   locale = ENG
then instead of AlgJavaMacro the set AlgJavaMacroRUS, or the set  AlgJavaMacroENG  is used.
 
Any set of macros is an skm-text containing a number of branches each of which represents one macro.
The macro name  is  the first word in the branch comment (until the first space or end of the comment). The macro body is the body (content) of the branch.
The macro body is included into  the current AlgJava program by
Alt+macroName.
For instance,
[]   is included by  
Alt+88
text println("_"); is included by Alt+pr
a sample program for screen graphics is included by Alt+gr
etc.

The user can make a new set of macros:
The new macro set will be activated at the next restart of the system.

During the current session one can also temporarily modify macro sets displayed in the LOG window. The contents of the window need not be saved, the added/changed macros can be used immediately.


Program Structure

An AlgJava program consists of primitive members (primitives) and sketches.

The following simple statements in Java are represented as primitives:

    Simple statement
    Typical general form  ([] - optional part)
variable declaration type variableName [= initial value expression];
method call statement methodName([argum1, argum2, ...]);
assignment statement
variableName [operation sign]= expression;
expression statement variableName++;    or    variableName--;
++variableName;    or     --variableName;
break statement break;          in loops and switches
continue statement continue;            in loops
return statement return;               in void method declarations (and also in the main part)
return ...;    in method declarations
throw statement throw new ...Exception(...);
empty statement ;


An empty primitive is created by the key Enter.
Usually, the primitive text consists of a single line. Though, if necessary, the new-line symbol may be inserted (by F6).
Simple statements cannot be split into several primitives.

The following Java structures (structural statements and method declarations) are represented as sketches:

   Structure Empty sketch
is created by
Empty branch
is added by

if statement
F1
F5
for statement
while statement

F2

method declaration
F3

switch statement
F4
F5
try-catch statement
Shift + F4
F5


Sketches are also used to form groups in AlgJava progams.

An AlgJava program consists of one or two parts: 

A demo-program without the second part (in the project AlgJavaDemo), see:
   Hello.algjava

The first part contains simple and structural statements. Method declarations can occur only in the second part, and cannot, in turn, contain any method declarations.
A demo-program having also a second part:
   Methods.algjava

In the case of more complex AlgJava programs some plug-ins can be roped in. Their names are listed (green) in the comment to the (first) branch of the program. The empty list of plug-ins is denoted by an underscore.


Editing

Only insertion edit mode is available.

One can use menu commands Edit>... , or common accelerators from the keyboard:
Ctrl+c - copy the selection to the  Amadeus_AlgJava clipboard;
Ctrl+v - paste from the Amadeus_AlgJava clipboard;
Ctrl+x - delete the selection (together with copying  to the  Amadeus_AlgJava clipboard);
Ctrl+z - undo;
Ctrl+y - redo.

Text from the system clipboard  is pasted (and also copied to the  Amadeus_AlgJava clipboard) by Edit>Bring

The roles of the keys Enter and F1 -- F6  are  described in the previous section.

In order to insert/paste a new primitive, a structural statement, or a break point  a f t e r  an existing structural statement, the cursor must be preliminarily moved to the very beginning of this structural statement.

Mouse left click:
Single: selects the closest integral construction (e.g. primitive text line, comment, branch, sketch). So, a click on the sketch line (left upper/bottom) corner selects the whole sketch; a click on the sketch line in front of a branch selects the branch.

Double: extends the selection if possible. So, double click on the sketch line  always selects the whole sketch;  double click on a primitive  always selects the whole primitive.

Mouse right click:
Single: iconify/deiconify (fold/unfold) currently selected sketch or branch.
Double:
iconify/deiconify (fold/unfold)  all sketches (or branches) at the level of the current selection.

Mouse drag:
selects constructions on the screen. Automatic scrolling is not  implemented.  In order to select bigger parts, one should previously (perhaps temporarily) form and fold groups of elements.


Using screen graphics


If the plug-in name raam is given at the beginning of an AlgJava program then  a predefined  graphic frame instance (raam) is accessible.  The instance method calls such as
   raam.setSize(..., ...);
   raam.setLocation(..., ...);
   raam.setTitle("...");     // Cyrillic letters allowed (Windows XP)
   raam.setVisible(true);
   raam.toFront();
can be used.

The frame raam includes a mouse-sensitive panel instance (of JPanel subclass Tahvel).
The drawing process must be described in a separate method with type void and signature

   joonistada(Tahvel t, Graphics g).
In the method joonistada method calls (related to the panel t and its graphic context g) such as
   t.setBackground(…);
   t.getSize();
       g.setColor(…);
   g.drawString(…);     // Cyrillic letters allowed
       g.drawOval(…); etc.
are used.
One can make use of the (invisible) name of the panel t:
   t.setName(s);   //  String s
   t.getName();      // returns the name  (null, if the name is not set yet)

Demo-programs using screen graphics:

   Graphics00.algjava
   Jewels.algjava
   GraphicsPalette.algjava
   OrnamentRek.algjava


Since the panel is mouse-sensitive, every mouse click on it invokes the method joonistada.

Note. It is not recommended to use console dialogue and screen graphics together.


Using console dialogue


If the plug-in name readln() is given at the beginning of an AlgJava program then the predefined method readln is available. If invoked, the latter waits until a sequence of characters (ending with Enter) is entered from keyboard, and then returns the input string.   A demo-program using console dialogue:
   Dialogue.algjava


Using text files


If the plug-in name I/O is given at the beginning of an AlgJava program then the predefined methods readerFrom and writerTo are available. See also the demo-program
   TextFileCopy.algjava.

A text file consists of lines of characters.

Let s be the name of an input text file.
A file reader is opened by
   BufferedReader reader = readerFrom(s);
The template of such statement can easily be included by the macro Alt+from.
Every next line (of type String) is read by
   reader.readLine();
the latter returns null, if there are no more lines to read from the file s.

Reader is closed by
   reader.close();


Let v be the name of an output text file.
A file writer is opened by

   PrintWriter writer = writerTo(v);
The template of such statement can easily be included by the macro Alt+to.
Every next line r (of type String) is appended to the output file by
   writer.println(r);
Writer  
is closed by
   writer.close();

All file-handling statements have to be included in a try-catch statement.
Corresponding template
can easily be included by macro Alt+io.


Debugging tools

If the plug-in name > is given at the beginning of an AlgJava program then break points can be used.
A break point primitive is inserted by the menu-command Insert>Break point (or F7).  The system  prefixes the break point 
by  > and displays the whole primitive in a special color.  The primitive text consists of a break point identifier (bpId) and  an (optional) inspection statement.
When the program flow reaches a break point then one line is output to the console consisting of:
After that,  the program execution process waits until the user presses Enter.
Note. In case of
performing (event-driven) screen graphics programs  the program execution continues without waiting for Enter.

The syntax of the break point primitive:
>  [bpId]  [inspection statement]
In bpId all characters are allowed except the space and quotation mark. 
There are two kinds of inspection statements:  inspect and inspectArray. Inspection statements in AlgJava programs  enable one to observe values of given variables and other expressions, or  values of all elements of a given array.   

The syntax of
the inspection statement inspect:
   inspect (colon argument)+
where argument is one of the following:
  1. simple variable
  2. array element  ( in the form  name[index expression] )
  3. (expression) 
Expression must not contain any quotation mark; parentheses may be omitted if the expression does not contain any square bracket.
Results from the inspection statement inspect: 
for each argument a colon followed by

  1.    name of the simple variable  =  value of the simple variable
  2.    index expression of the array element = value of the index expression    and     array element = value of the array element; if the index expression is an integer literal then its value is not shown (i.e. repeated)
  3.    given expression = value of the expression .
Examples
      Break point (in method mtd)
      Sample results on console
> A inspect :k  :y  :i
mtd>A: k = -234 : y = 13.075 : i = 3
> B inspect :a[0]  :a[i-1] mtd>B:  a[0] = 20 : i-1 = 2 a[i-1] = 40
> area inspect :Math.PI * y * y mtd>area: Math.PI * y * y = 537.0729355898515
> below_100? inspect :(a[0]+a[i-1]/8)
mtd>below_100?: (a[0] + a[i-1]/8) = 25
> inspect :i  :y
mtd>: i = 3 : y = 13.075
> start_of_inner_loop
mtd>start_of_inner_loop:


The syntax of inspection statement inspectArray:
   inspectArray colon arrayName

The single argument is a name (pointer) to an one-dimensional array.
Results from the inspection statement inspect:
 : arrayName[]: values of all elements of the array

Examples
      Break point (in method mtd)       Sample results on console
> before_loop inspectArray :a
mtd>before_loop:a[]: 30  320  -40  50
> after_loop inspectArray :a mtd>after_loop:a[]: -40  30  50  320
> i-th_row inspectArray :table[i] mtd>i-th_row:table[i][]: 0  -310  0  725  -1



If the plug-in name > is not given at the beginning of an AlgJava program then all break points in the program are simply ignored.

All break points are removed from the program (selected part) by the menu-command  Tools>Reduce.





Groups and comments

In an AlgJava program, arbitrary groups of sequential members (and groups) can be formed.  However, "mixed" groups that   would include both (last) members in first part and a (first) method declaration in the second part are forbidden.
In order to form a group:
Executing the program does not depend on the manner in which its members are grouped.
Any group can be given a name -- as comment of the sketch. The name remains visible on the screen even after folding (iconifying) the sketch. 
In order to open a group: select the sketch and  apply the menu-command  Edit>Toggle  (or Ctrl+t). Only unnamed groups can be opened.
In order to comment out an entire group its name is prefixed by two slashes. Such group is ignored while composing the corresponding Java program.
In order to comment out a primitive its text is prefixed by two slashes. Such text is transferred to the corresponding Java program (as a line comment).
Primitive text is commented by an extra (green) line of characters. It is transferred to the corresponding Java program (as a line end-comment).
One can add comments to sketches representing structural statements and method declarations placing them at the beginning of the sketch and/or its branch(es).  Such comments (other than labels of structural statements) are not transferred to the corresponding Java program.
See also the demo-program  Jewels.algjava.




Advanced topics

Import and static variables declarations

One can insert import and static variables declarations at the beginning of an AlgJava program. For instance:

import javax.swing.JOptionPane;    //  import declaration

static boolean on = true;        // declaration of a static variable  (on)
 

A static variable is accessible from any method, incl the main method.

It is not allowed to enclose import and static variables declarations into a group.


Labeled control statements

The label of a structural statement may be written as the sketch comment at the beginning of the sketch . The label must be a unique (inside the program scope) Java-identifier. It is transferred to the corresponding Java program and suffixed by a colon. 
At any deeper level of a labeled statement one can use
   break label;    // breaks the execution of this statement
or, in case of loop statement,
   continue label;
// breaks the execution of the body of this loop statement


System properties

System properties are defined in the file Amadeus.properties and reckoned with at every start of the system.
NB! The separator '\' is doubled ('/' -- not).


Property key
Form
Purpose
Example
AmadeusDirectory
Full path
Path to  Amadeus_AlgJava home folder
AmadeusDirectory = D:\\AlgJava

defaultOpenDirectory

Full path; current (.) by default
Otsimistee algus failidialoogides

defaultOpenDirectory = D:\\AlgJava\\Portfolio

myMacros

( fName[.type] )+

type = html by default

List of macro sets to be activated
myMacros = AltGrMacro AlgJavaMacro
startProject Project description file name;
type = html by default
Project to be initially opened
startProject = AlgJavaWorks

defaultFont

Font
name, style, size

style:

0-plain / 1-bold /

2-italic/ 3-bolditalic

Default font for screen
defaultFont = Times New Roman, 1, 14

iconImageFileName

By default: AmadeusDirectory
\\gif\\collapsed.gif
Name of the file,  containing the  icon picture

iconImageFileName = D:\\Algjava\\gif\\collapsed2.gif

autoSaveTimePeriod

Unsigned integer; 1 by default

Period (in minutes) for autosave

autoSaveTimePeriod = 3

locale

ENG | EST | RUS
By default
:
ENG

User interface language

locale = EST

selectionIntensity
LIGHT | DARK
By default: DARK
Selection color intensity
selectionIntensity = LIGHT


Migration between operating systems

NB! In case of shared file system, a separate AlgJava home folder  is needed for every operating system (OS).

Migration from OS A to OS B:

Suppose:
AlgJavaA is the AlgJava home folder under A
AlgJavaB is the AlgJava home folder under B

In order to make use (
under B) of programs (earlier) composed and saved in AlgJavaA|workspace (where | stands for separator,  \  or  / ) the programs should be transferred and their names included into project (B). More precisely:
 
 
1. Create AlgJava home folder AlgJavaB (if not created yet).

2. Transfer (necessary) programs *.algjava:
  
AlgJavaA|workspace ==> AlgJavaB|workspace  

3. In home folder AlgJavaB, start (
under B) Amadeus_AlgJava as usual.

4. Open project AlgJavaWorks (if not open yet), supplement the list of programs, e. g:
   Frame>New
   File>Import  ...
AlgJavaA|Protfolio|AlgJavaWorks.html
   Select names of the programs, copy (Ctrl+c).
   Go to the project window (B), paste (Ctrl+v).
   Save project (B): Fail>Export ...
AlgJavaB|AlgJavaWorks.html

5. If necessary, transfer also user's macro set(s):
   
AlgJavaA|macros|MyAlgJavaMacro.html ==> AlgJavaB|macros|MyAlgJavaMacro.html

6. If necessary, edit
AlgJavaB|Amadeus.properties following the example of AlgJavaA|Amadeus.properties.
These properties will be reckoned at the next start of the system. 

Action descriptions in project

Actions descriptions are located in the first branch of the project. (The second branch contains the list of  AlgJava programs belonging to the project.)
 The first branch consists of three sections (sub-sketches) named  Paths, Open-script and  Save-script.
In the following, the meaning of these sections
is explained. The project  AlgJavaDemo is taken as basis for the elucidation. The other project (AlgJavaWorks) is quite similar.

In the first section (Paths) the names 
Kaust,  JavaComp, JavaRun and  JavaRunGr are declared:
Paths   
    Kaust: .\demo
                                       
--- for Linux and SunOS:
Kaust: ./demo
    JavaComp: javac -sourcepath "{Kaust}" -classpath "{Kaust}" -d   "{Kaust}"
    JavaRun: runMain.bat "{Kaust}"

    JavaRunGr: java -cp "{Kaust}" Main
--- for Linux and SunOS: runMainGr.bat "{Kaust}"

In the second section (Open-script) the menu commands are given which will be performed  in case of opening a program In the projects AlgJavaDemo and AlgJavaWorks only one menu command is specified:
Open-script
   Import: path=Kaust      
--- import an AlgJava program from the folder
(demo) specified by Kaust.

In the third section (Save-script) the menu commands and a process (command line) are given which will be performed  in accord to File>Save in the window of the current program.

In the following, it is assumed that the current program name is pr.algjava.

Save-script --- Windows 
  
Export plain-HTML: path=Kaust
--- export the current
AlgJava program pr.algjava into the folder Kaust
   Textualize+Write text: path=Kaust ext=java
--- textualize 
the current AlgJava program and write the result pr.java  into the folder Kaust
   Process:
" {JavaComp} path=Kaust ext=java
            && start "KONSOOL" {JavaRun} arg0 arg1 ... arg7 "

--- 1) compile 
pr.java from the folder Kaust (if sucess, save the result Main.class into the folder Kaust)
--- 2) open a new console window (titled KONSOOL) and 
--- 3) perform runMain.bat .\demo arg0 arg1 ... arg7
Save-script  
--- Linux and SunOS
   Export plain-HTML: path=Kaust
--- export the current AlgJava program pr.algjava into the folder Kaust  
   Textualize+Write text: path=Kaust ext=java
--- textualize  the current AlgJava program and write the result pr.java  into the folder Kaust
   Process: " export LANG=et_EE.iso8859-15     --- is missing for SunOS
            && {JavaComp} path=Kaust ext=java
            && sh {JavaRun} arg0 arg1 ... arg7 "
--- (1) set environment variable
LANG
--- 2)
compile  pr.java from the folder Kaust (if sucess, save the result Main.class into the folder Kaust)
--- 3)
perform runMain.bat ./demo arg0 arg1 ... arg7

Command file
runMain.bat --Windows XP:

echo off
IF NOT EXIST "%systemroot%\system32\tasklist.exe" GOTO NOTASKLIST
IF NOT EXIST x.bat ECHO REM>x.bat
x 2> log1.txt 1>log.txt & ECHO REM > x.bat && tasklist /nh /fi "Imagename eq cmd.exe" |
java -cp . GetPID_WinXP > x.bat && java -cp %1 Main %2 %3 %4 %5 %6 %7 %8 %9
GOTO END
:NOTASKLIST
java -cp %1 Main %2 %3 %4 %5 %6 %7 %8 %9
:END

If 
tasklist  and taskkill are not available (as in Home Edition) the previous console window cannot not be killed,  and one can make use of the simpler command file:
echo off
java -cp %1 Main %2 %3 %4 %5 %6 %7 %8 %9

If  tasklist  and taskkill are certainly available (as in Professional Edition) then the previous console window will  be killed,  and one can make use of the simpler command file:
echo off
IF NOT EXIST x.bat ECHO REM>x.bat
x 2> log1.txt 1>log.txt & ECHO REM > x.bat && tasklist /nh /fi "Imagename eq cmd.exe" |
java -cp . GetPID_WinXP > x.bat && java -cp %1 Main %2 %3 %4 %5 %6 %7 %8 %9


 
runMain.bat  --Linux:
xterm -hold -geometry 100x60+100+100 -e java -cp $1 Main $2 $3 $4 $5 $6 $7 $8 $9

runMain.bat
   --SunOS:
xterm  -geometry 100x60+100+100 -e java -cp $1 Main $2 $3 $4 $5 $6 $7 $8 $9

Recommendation. If the console window is redundant (usually in case of  screen graphics programs) one could use
JavaRunGr instead of  JavaRun in the section Save-script.
It means that
in case of Linuxi and SunOS the command file 
runMainGr.bat :
 
   xterm -e java -cp $1 Main $2 $3 $4 $5 $6 $7 $8 $9
in case of Windows simply the command :
   java -cp "{Kaust}"
Main
is performed.


Images

Since version 70423 some (restricted) tools for image processing are available. It is possible to insert/remove images into/from AlgJava texts.  Usually, images do not affect semantics.
Image files (*.gif, *.jpg, ...) are located in the folder gif / pro
It is not allowed to insert images into an AlgJava program currently opened from a project.




Class Math:  method summary

Method Summary

static double

abs(double a)
          Returns the absolute value of a
double value.

static float

abs(float a)
          Returns the absolute value of a
float value.

static int

abs(int a)
          Returns the absolute value of an
int value.

static long

abs(long a)
          Returns the absolute value of a
long value.

static double

acos(double a)
          Returns the arc cosine of an angle, in the range of 0.0 through pi.

static double

asin(double a)
          Returns the arc sine of an angle, in the range of -pi/2 through pi/2.

static double

atan(double a)
          Returns the arc tangent of an angle, in the range of -pi/2 through pi/2.

static double

atan2(double y, double x)
          Converts rectangular coordinates (
xy) to polar (r, theta).

static double

cbrt(double a)
          Returns the cube root of a
double value.

static double

ceil(double a)
          Returns the smallest (closest to negative infinity)
double value that is greater than or equal to the argument and is equal to a mathematical integer.

static double

cos(double a)
          Returns the trigonometric cosine of an angle.

static double

cosh(double x)
          Returns the hyperbolic cosine of a
double value.

static double

exp(double a)
          Returns Euler's number e raised to the power of a
double value.

static double

expm1(double x)
          Returns ex -1.

static double

floor(double a)
          Returns the largest (closest to positive infinity)
double value that is less than or equal to the argument and is equal to a mathematical integer.

static double

hypot(double x, double y)
          Returns sqrt(x2 +y2) without intermediate overflow or underflow.

static double

IEEEremainder(double f1, double f2)
          Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard.

static double

log(double a)
          Returns the natural logarithm (base e) of a
double value.

static double

log10(double a)
          Returns the base 10 logarithm of a
double value.

static double

log1p(double x)
          Returns the natural logarithm of the sum of the argument and 1.

static double

max(double a, double b)
          Returns the greater of two
double values.

static float

max(float a, float b)
          Returns the greater of two
float values.

static int

max(int a, int b)
          Returns the greater of two
int values.

static long

max(long a, long b)
          Returns the greater of two
long values.

static double

min(double a, double b)
          Returns the smaller of two
double values.

static float

min(float a, float b)
          Returns the smaller of two
float values.

static int

min(int a, int b)
          Returns the smaller of two
int values.

static long

min(long a, long b)
          Returns the smaller of two
long values.

static double

pow(double a, double b)
          Returns the value of the first argument raised to the power of the second argument.

static double

random()
          Returns a
double value with a positive sign, greater than or equal to 0.0 and less than 1.0.

static double

rint(double a)
          Returns the
double value that is closest in value to the argument and is equal to a mathematical integer.

static long

round(double a)
          Returns the closest
long to the argument.

static int

round(float a)
          Returns the closest
int to the argument.

static double

signum(double d)
          Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.

static float

signum(float f)
          Returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.

static double

sin(double a)
          Returns the trigonometric sine of an angle.

static double

sinh(double x)
          Returns the hyperbolic sine of a
double value.

static double

sqrt(double a)
          Returns the correctly rounded positive square root of a
double value.

static double

tan(double a)
          Returns the trigonometric tangent of an angle.

static double

tanh(double x)
          Returns the hyperbolic tangent of a
double value.

static double

toDegrees(double angrad)
          Converts an angle measured in radians to an approximately equivalent angle measured in degrees.

static double

toRadians(double angdeg)
          Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

static double

ulp(double d)
          Returns the size of an ulp of the argument.

static float

ulp(float f)
          Returns the size of an ulp of the argument.

 



Class String: method summary

Method Summary

 char

charAt(int index)
          Returns the
char value at the specified index.

 int

codePointAt(int index)
          Returns the character (Unicode code point) at the specified index.

 int

codePointBefore(int index)
          Returns the character (Unicode code point) before the specified index.

 int

codePointCount(int beginIndex, int endIndex)
          Returns the number of Unicode code points in the specified text range of this
String.

 int

compareTo(String anotherString)
          Compares two strings lexicographically.

 int

compareToIgnoreCase(String str)
          Compares two strings lexicographically, ignoring case differences.

 String

concat(String str)
          Concatenates the specified string to the end of this string.

 boolean

contains(CharSequence s)
          Returns true if and only if this string contains the specified sequence of char values.

 boolean

contentEquals(CharSequence cs)
          Returns
true if and only if this String represents the same sequence of char values as the specified sequence.

 boolean

contentEquals(StringBuffer sb)
          Returns
true if and only if this String represents the same sequence of characters as the specified StringBuffer.

static String

copyValueOf(char[] data)
          Returns a String that represents the character sequence in the array specified.

static String

copyValueOf(char[] data, int offset, int count)
          Returns a String that represents the character sequence in the array specified.

 boolean

endsWith(String suffix)
          Tests if this string ends with the specified suffix.

 boolean

equals(Object anObject)
          Compares this string to the specified object.

 boolean

equalsIgnoreCase(String anotherString)
          Compares this
String to another String, ignoring case considerations.

static String

format(Locale l, String format, Object... args)
          Returns a formatted string using the specified locale, format string, and arguments.

static String

format(String format, Object... args)
          Returns a formatted string using the specified format string and arguments.

 byte[]

getBytes()
          Encodes this
String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

 void

getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
          Deprecated. This method does not properly convert characters into bytes. As of JDK 1.1, the preferred way to do this is via the
getBytes() method, which uses the platform's default charset.

 byte[]

getBytes(String charsetName)
          Encodes this
String into a sequence of bytes using the named charset, storing the result into a new byte array.

 void

getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
          Copies characters from this string into the destination character array.

 int

hashCode()
          Returns a hash code for this string.

 int

indexOf(int ch)
          Returns the index within this string of the first occurrence of the specified character.

 int

indexOf(int ch, int fromIndex)
          Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.

 int

indexOf(String str)
          Returns the index within this string of the first occurrence of the specified substring.

 int

indexOf(String str, int fromIndex)
          Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

 String

intern()
          Returns a canonical representation for the string object.

 int

lastIndexOf(int ch)
          Returns the index within this string of the last occurrence of the specified character.

 int

lastIndexOf(int ch, int fromIndex)
          Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.

 int

lastIndexOf(String str)
          Returns the index within this string of the rightmost occurrence of the specified substring.

 int

lastIndexOf(String str, int fromIndex)
          Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.

 int

length()
          Returns the length of this string.

 boolean

matches(String regex)
          Tells whether or not this string matches the given regular expression.

 int

offsetByCodePoints(int index, int codePointOffset)
          Returns the index within this
String that is offset from the given index by codePointOffset code points.

 boolean

regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
          Tests if two string regions are equal.

 boolean

regionMatches(int toffset, String other, int ooffset, int len)
          Tests if two string regions are equal.

 String

replace(char oldChar, char newChar)
          Returns a new string resulting from replacing all occurrences of
oldChar in this string with newChar.

 String

replace(CharSequence target, CharSequence replacement)
          Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.

 String

replaceAll(String regex, String replacement)
          Replaces each substring of this string that matches the given regular expression with the given replacement.

 String

replaceFirst(String regex, String replacement)
          Replaces the first substring of this string that matches the given regular expression with the given replacement.

 String[]

split(String regex)
          Splits this string around matches of the given regular expression.

 String[]

split(String regex, int limit)
          Splits this string around matches of the given regular expression.

 boolean

startsWith(String prefix)
          Tests if this string starts with the specified prefix.

 boolean

startsWith(String prefix, int toffset)
          Tests if this string starts with the specified prefix beginning a specified index.

 CharSequence

subSequence(int beginIndex, int endIndex)
          Returns a new character sequence that is a subsequence of this sequence.

 String

substring(int beginIndex)
          Returns a new string that is a substring of this string.

 String

substring(int beginIndex, int endIndex)
          Returns a new string that is a substring of this string.

 char[]

toCharArray()
          Converts this string to a new character array.

 String

toLowerCase()
          Converts all of the characters in this
String to lower case using the rules of the default locale.

 String

toLowerCase(Locale locale)
          Converts all of the characters in this
String to lower case using the rules of the given Locale.

 String

toString()
          This object (which is already a string!) is itself returned.

 String

toUpperCase()
          Converts all of the characters in this
String to upper case using the rules of the default locale.

 String

toUpperCase(Locale locale)
          Converts all of the characters in this
String to upper case using the rules of the given Locale.

 String

trim()
          Returns a copy of the string, with leading and trailing whitespace omitted.

static String

valueOf(boolean b)
          Returns the string representation of the
boolean argument.

static String

valueOf(char c)
          Returns the string representation of the
char argument.

static String

valueOf(char[] data)
          Returns the string representation of the
char array argument.

static String

valueOf(char[] data, int offset, int count)
          Returns the string representation of a specific subarray of the
char array argument.

static String

valueOf(double d)
          Returns the string representation of the
double argument.

static String

valueOf(float f)
          Returns the string representation of the
float argument.

static String

valueOf(int i)
          Returns the string representation of the
int argument.

static String

valueOf(long l)
          Returns the string representation of the
long argument.

static String

valueOf(Object obj)
          Returns the string representation of the
Object argument.

 



Class Integer: method summary

Method Summary

static int

bitCount(int i)
          Returns the number of one-bits in the two's complement binary representation of the specified
int value.

 byte

byteValue()
          Returns the value of this
Integer as a byte.

 int

compareTo(Integer anotherInteger)
          Compares two
Integer objects numerically.

static Integer

decode(String nm)
          Decodes a
String into an Integer.

 double

doubleValue()
          Returns the value of this
Integer as a double.

 boolean

equals(Object obj)
          Compares this object to the specified object.

 float

floatValue()
          Returns the value of this
Integer as a float.

static Integer

getInteger(String nm)
          Determines the integer value of the system property with the specified name.

static Integer

getInteger(String nm, int val)
          Determines the integer value of the system property with the specified name.

static Integer

getInteger(String nm, Integer val)
          Returns the integer value of the system property with the specified name.

 int

hashCode()
          Returns a hash code for this
Integer.

static int

highestOneBit(int i)
          Returns an
int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified int value.

 int

intValue()
          Returns the value of this
Integer as an int.

 long

longValue()
          Returns the value of this
Integer as a long.

static int

lowestOneBit(int i)
          Returns an
int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified int value.

static int

numberOfLeadingZeros(int i)
          Returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified
int value.

static int

numberOfTrailingZeros(int i)
          Returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified
int value.

static int

parseInt(String s)
          Parses the string argument as a signed decimal integer.

static int

parseInt(String s, int radix)
          Parses the string argument as a signed integer in the radix specified by the second argument.

static int

reverse(int i)
          Returns the value obtained by reversing the order of the bits in the two's complement binary representation of the specified
int value.

static int

reverseBytes(int i)
          Returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified
int value.

static int

rotateLeft(int i, int distance)
          Returns the value obtained by rotating the two's complement binary representation of the specified
int value left by the specified number of bits.

static int

rotateRight(int i, int distance)
          Returns the value obtained by rotating the two's complement binary representation of the specified
int value right by the specified number of bits.

 short

shortValue()
          Returns the value of this
Integer as a short.

static int

signum(int i)
          Returns the signum function of the specified
int value.

static String

toBinaryString(int i)
          Returns a string representation of the integer argument as an unsigned integer in base 2.

static String

toHexString(int i)
          Returns a string representation of the integer argument as an unsigned integer in base 16.

static String

toOctalString(int i)
          Returns a string representation of the integer argument as an unsigned integer in base 8.

 String

toString()
          Returns a
String object representing this Integer's value.

static String

toString(int i)
          Returns a
String object representing the specified integer.

static String

toString(int i, int radix)
          Returns a string representation of the first argument in the radix specified by the second argument.

static Integer

valueOf(int i)
          Returns a
Integer instance representing the specified int value.

static Integer

valueOf(String s)
          Returns an
Integer object holding the value of the specified String.

static Integer

valueOf(String s, int radix)
          Returns an
Integer object holding the value extracted from the specified String when parsed with the radix given by the second argument.


 



Class Double: method summary

Method Summary

 byte

byteValue()
          Returns the value of this
Double as a byte (by casting to a byte).

static int

compare(double d1, double d2)
          Compares the two specified
double values.

 int

compareTo(Double anotherDouble)
          Compares two
Double objects numerically.

static long

doubleToLongBits(double value)
          Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout.

static long

doubleToRawLongBits(double value)
          Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout, preserving Not-a-Number (
NaN) values.

 double

doubleValue()
          Returns the
double value of this Double object.

 boolean

equals(Object obj)
          Compares this object against the specified object.

 float

floatValue()
          Returns the
float value of this Double object.

 int

hashCode()
          Returns a hash code for this
Double object.

 int

intValue()
          Returns the value of this
Double as an int (by casting to type int).

 boolean

isInfinite()
          Returns
true if this Double value is infinitely large in magnitude, false otherwise.

static boolean

isInfinite(double v)
          Returns
true if the specified number is infinitely large in magnitude, false otherwise.

 boolean

isNaN()
          Returns
true if this Double value is a Not-a-Number (NaN), false otherwise.

static boolean

isNaN(double v)
          Returns
true if the specified number is a Not-a-Number (NaN) value, false otherwise.

static double

longBitsToDouble(long bits)
          Returns the
double value corresponding to a given bit representation.

 long

longValue()
          Returns the value of this
Double as a long (by casting to type long).

static double

parseDouble(String s)
          Returns a new
double initialized to the value represented by the specified String, as performed by the valueOf method of class Double.

 short

shortValue()
          Returns the value of this
Double as a short (by casting to a short).

static String

toHexString(double d)
          Returns a hexadecimal string representation of the
double argument.

 String

toString()
          Returns a string representation of this
Double object.

static String

toString(double d)
          Returns a string representation of the
double argument.

static Double

valueOf(double d)
          Returns a
Double instance representing the specified double value.

static Double

valueOf(String s)
          Returns a
Double object holding the double value represented by the argument string s

 



Class Grapics: method summary

Method Summary

abstract  void

clearRect(int x, int y, int width, int height)
          Clears the specified rectangle by filling it with the background color of the current drawing surface.

abstract  void

clipRect(int x, int y, int width, int height)
          Intersects the current clip with the specified rectangle.

abstract  void

copyArea(int x, int y, int width, int height, int dx, int dy)
          Copies an area of the component by a distance specified by dx and dy.

abstract  Graphics

create()
          Creates a new Graphics object that is a copy of this Graphics object.

 Graphics

create(int x, int y, int width, int height)
          Creates a new Graphics object based on this Graphics object, but with a new translation and clip area.

abstract  void

dispose()
          Disposes of this graphics context and releases any system resources that it is using.

 void

draw3DRect(int x, int y, int width, int height, boolean raised)
          Draws a 3-D highlighted outline of the specified rectangle.

abstract  void

drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Draws the outline of a circular or elliptical arc covering the specified rectangle.

 void

drawBytes(byte[] data, int offset, int length, int x, int y)
          Draws the text given by the specified byte array, using this graphics context's current font and color.

 void

drawChars(char[] data, int offset, int length, int x, int y)
          Draws the text given by the specified character array, using this graphics context's current font and color.

abstract  boolean

drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
          Draws as much of the specified image as is currently available.

abstract  boolean

drawImage(Image img, int x, int y, ImageObserver observer)
          Draws as much of the specified image as is currently available.

abstract  boolean

drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
          Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.

abstract  boolean

drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
          Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.

abstract  boolean

drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
          Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.

abstract  boolean

drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
          Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.

abstract  void

drawLine(int x1, int y1, int x2, int y2)
          Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

abstract  void

drawOval(int x, int y, int width, int height)
          Draws the outline of an oval.

abstract  void

drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Draws a closed polygon defined by arrays of x and y coordinates.

 void

drawPolygon(Polygon p)
          Draws the outline of a polygon defined by the specified Polygon object.

abstract  void

drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
          Draws a sequence of connected lines defined by arrays of x and y coordinates.

 void

drawRect(int x, int y, int width, int height)
          Draws the outline of the specified rectangle.

abstract  void

drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draws an outlined round-cornered rectangle using this graphics context's current color.

abstract  void

drawString(AttributedCharacterIterator iterator, int x, int y)
          Draws the text given by the specified iterator, using this graphics context's current color.

abstract  void

drawString(String str, int x, int y)
          Draws the text given by the specified string, using this graphics context's current font and color.

 void

fill3DRect(int x, int y, int width, int height, boolean raised)
          Paints a 3-D highlighted rectangle filled with the current color.

abstract  void

fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Fills a circular or elliptical arc covering the specified rectangle.

abstract  void

fillOval(int x, int y, int width, int height)
          Fills an oval bounded by the specified rectangle with the current color.

abstract  void

fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Fills a closed polygon defined by arrays of x and y coordinates.

 void

fillPolygon(Polygon p)
          Fills the polygon defined by the specified Polygon object with the graphics context's current color.

abstract  void

fillRect(int x, int y, int width, int height)
          Fills the specified rectangle.

abstract  void

fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Fills the specified rounded corner rectangle with the current color.

 void

finalize()
          Disposes of this graphics context once it is no longer referenced.

abstract  Shape

getClip()
          Gets the current clipping area.

abstract  Rectangle

getClipBounds()
          Returns the bounding rectangle of the current clipping area.

 Rectangle

getClipBounds(Rectangle r)
          Returns the bounding rectangle of the current clipping area.

 Rectangle

getClipRect()
          Deprecated. As of JDK version 1.1, replaced by getClipBounds().

abstract  Color

getColor()
          Gets this graphics context's current color.

abstract  Font

getFont()
          Gets the current font.

 FontMetrics

getFontMetrics()
          Gets the font metrics of the current font.

abstract  FontMetrics

getFontMetrics(Font f)
          Gets the font metrics for the specified font.

 boolean

hitClip(int x, int y, int width, int height)
          Returns true if the specified rectangular area might intersect the current clipping area.

abstract  void

setClip(int x, int y, int width, int height)
          Sets the current clip to the rectangle specified by the given coordinates.

abstract  void

setClip(Shape clip)
          Sets the current clipping area to an arbitrary clip shape.

abstract  void

setColor(Color c)

          Sets this graphics context's current color to the specified color.

abstract  void

setFont(Font font)
          Sets this graphics context's font to the specified font.

abstract  void

setPaintMode()
          Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color.

abstract  void

setXORMode(Color c1)
          Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color.

 String

toString()
          Returns a String object representing this Graphics object's value.

abstract  void

translate(int x, int y)
          Translates the origin of the graphics context to the point (x, y) in the current coordinate system.