Contents | Prev | Next | Index


Access from Java Programs

All Java classes and its members, as generated by Oberon-2, can be imported and accessed by third party Java software as long as they stick to the naming conventions and parameter passing rules which are described below.

A Canterbury Oberon-2 module is compiled into a single Java source file which contains a single class of the same name. Each record type declared in the Oberon-2 module is mapped to a Java class file, using the name <program-name>_<class-name>.

Example: Given the Oberon-2 module

MODULE Example;
  ....
TYPE MYREC = RECORD .... END;
  ....
END.

the Oberon-2 compiler generates the following 2 files:

  1. Example.class 
  2. Example_MYREC.class

Oberon-2 procedures are mapped to corresponding static class methods in the Java output class. Type-bound procedures are mapped to Java virtual methods.

Value parameters for procedures and methods are directly mapped to Java's value parameters using the corresponding Java types. If they are of structured types then the called method creates local copies. Variable parameters which are structured are mapped to Java reference parameters. Unstructured variable parameters are passed by reference using arrays of one element. For example, in order to pass a Java value xval of type double to an Oberon-2 procedure whose formal type is declared as a VAR-parameter, the following Java code is required: 

double xval = 3.1415;
double[] px = new double[1];
px[0] = xval;
<oberon-module-id>.<oberon-proc-id>( px );
xval = px[0];

The following 2 tables list all value and variable parameter types for Oberon-2 and their corresponding Java equivalents:

 
Oberon-2 value parameter
Java parameter
CHAR char
BOOLEAN boolean
SHORTINT byte
INTEGER short
LONGINT int
SYSTEM.HUGEINT long
REAL float
LONGREAL double
SYSTEM.PTR java.lang.Object
<record-type-id> <record-type-id>
<class-type-id> <module-id>_<class-type-id>
<array-type-id> <element-type-id>[]<...>[]
<pointer-type-id> <pointee record-type-id> or <element-type-id>[]<...>[]

 

Oberon-2 variable parameter
Java parameter
CHAR char[]
BOOLEAN boolean[]
SHORTINT byte[]
INTEGER short[]
LONGINT int[]
SYSTEM.HUGEINT long[]
REAL float[]
LONGREAL double[]
SYSTEM.PTR java.lang.Object[]
<record-type-id> <record-type-id>
<class-type-id> <module-id>_<class-type-id>
<array-type-id> <element-type>[]<...>[]
<pointer-type-id> <Java signature of pointee type>[]


Contents | Prev | Next | Index

Canterbury Oberon-2 for JVM  (Last documentation update Jun 2, 2000)
Copyright © 1998 Mill Hill & Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to mhc@webcom.com