Variables
The JVM stores data in fields. For every variable and constant a field record is created in the class file together with a field reference in the constant pool. Methods access the field via the field reference and address the field reference via its index in the constant pool.
You can create class fields (static = global for the class) and instance fields (accessible in objects).
A variable has a type. There are basic Java types and class types.
HolonJ creates a public instance field, if no attributes are given.
Syntax: (attributes) type identifier
int xxx
private Point origin
static long sum
Constants are final static fields with a fixed value.
Syntax: value final type identifier
88 final int Maximum
The use of arrays in HolonJ is best described with some examples.
int [] [] intarray
defines a two dimensional array.
2 3 new intarray
creates an instance of intarray with lengths 2 and 3
77 is 0 1 intarray
stores a value at component 0,1
0 1 intarray
retrieves the value at component 0,1
obj intarray
delivers the object reference, e.g. for passing the array as an argument to another word.
length intarray
delivers the number of components of a one dim. array
\ Print all components of the string array args
: main ( string [] args -- )
length args times i args type loop ;
Syntax: type name.
: startFrame ( -- )
frame myframe \ defines the local variable myframe of type frame
new myframe ( -- ) \ creates an instance of myframe
new Calculator () myframe addComponent
myframe packWindow ;
"()" can be used in place of "( -- )". Some constructors accept initial values. Example:
10 new myList ( int -- )
Local arrays are defined and used like other arrays.
Fields in external packages are imported.
1998-2013 Wolf Wejgaard