Interoperational Java Integration Interoperational Java Integration

n the past, 4GL applications could only interoperate directly (without the use of SOAP) with C sources. The latest enhancement to the Lycia 4GL development language is the integration of the Java Language Interoperation. This exciting new interface provides 4GL application vendors with the ability to implement diverse software development projects by inter-operating with Java programs and modules. Java is currently the most used development platform and it is therefore no surprise, that Lycia can now fully utilize Java classes to conform with this standardization.


The Java interoperational interface is based on the JNI framework which allows your native 4GL to use Java objects in the same way that Java code uses these objects. A native method can create Java objects and then inspect and use these objects to perform its tasks. 4GL can also inspect and use objects created by the Java application code.


This latest addition also comes with huge economic consequences for your software management as you are now able to develop with 4GL, Java and C sources in co-existence to build powerful enterprise business applications. 

 

Interoperational Language Integration    

Requirements

You only need to have the Java JRE installed on your Lycia Development system because the Java interface utilizes the already compiled .class files or Java packages containing .class files. The location of the pool of Java classes is simply specified by a CLASSPATH variable or command line argument.


Importing a Java Class

To use a Java class within a 4GL program, you simply import it as a normal line of 4gl code using the following syntax:

IMPORT JAVA <ClassName>

 

 

 

Unique native data type handling

Another unique feature of Lycia’s Java interoperation is the data type handling. Data passing and retrieving (returning) to and from Java methods/objects does not require the use of any special non-4gl-standard data types. The entire data mapping operations including array handling are done transparently which allows the developer to use the standard native 4GL data types and syntax. 

Java Object definition, creation and scope


Java objects are defined just like any other 4gl data types by using the fully qualified class name for the data type. To create an instance, simply use the create() method.

The scope of a reference to a Java Class can be modular or global.

IMPORT JAVA java.lang.StringBuffer
...
DEFINE sb StringBuffer
LET sb = StringBuffer.create()


Lycia 4GL <-> Java data type mapping

4GL Data Types   Java Data Types
CHAR
VARCHAR
NCHAR
NVARCHAR
STRING
TEXT
java.lang.String
TINYINTbyte
SMALLINTshort
INTEGERint
BIGINTlong
BOOLEANboolean
SMALLFLOATfloat
FLOATdouble
DECIMAL
MONEY
java.math.BigDecimal
DATE
DATETIME
javax.xml.datatype.XMLGregorianCalendar
INTERVALjavax.xml.datatype.Duration
BYTEbyte[ ]

 

Example:

We have got following Java Class


public class SimpleClass {
private int val;
public SimpleClass() {
}
public SimpleClass(int val) {
this.val = val;
}
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
public static int getValsSum(SimpleClass v1, SimpleClass v2){
return v1.getVal() + v2.getVal();
}
}


And together with the Java interface implementation, Lycia offers much more to make your applications universal and fit for any environment:


Language Compatibility

…and in this 4gl code, we will use our Java class:


IMPORT JAVA SimpleClass -- class is imported
MAIN
DEFINE s, s1 SimpleClass,
i, i1, param INT,
ii BIGINT,
ch CHAR

PROMPT "Enter the parameter for SimpleClass object s: "

FOR param

# constructor SimpleClass(int val) is invoked
LET s = SimpleClass.create(param)

# constructor SimpleClass() is invoked
LET s1=SimpleClass.create() 

# these are object methods without parameters
LET i=s.getVal()
LET i1=s1.getVal()
DISPLAY "The initial value of the object s  = ", i

AT 3,2
DISPLAY "The initial value of the object s1 = ", i1

AT 4,2

INITIALIZE param TO NULL
PROMPT "Enter the new value for SimpleClass object s1: "

FOR param

# this is an object methods with parameters
CALL s1.setVal(param)
LET i1=s1.getVal()
DISPLAY "The new value of the object s1 = ", i1 AT 4,2

# method getValSum is a class method,

# because it has 'static' keyword
LET ii = SimpleClass.getValsSum(s,s1)
DISPLAY "The getValPow() method returns: s1+s2 = ", ii

AT 6,2

PROMPT "Press any key to exit..." FOR CHAR ch
END MAIN

 

Note: to watch the online video guides you should have the Adobe Flash player installed on your computer. You can download and install this plugin from the Adobe Company web site.