As with all IDL objects, a Java object is created using the IDL OBJ_NEW function. Keying off the provided Java class name, the underlying implementation uses the IDL Java subsystem to call the constructor on the desired Java object. The following line of code demonstrates the basic syntax for calling OBJ_NEW to create a Java object within IDL:

oJava = OBJ_NEW('IDLjavaObject$JAVACLASSNAME', 'JavaClassName' [, Arg1, Arg2, ..., ArgN])

where JAVACLASSNAME is the class name token used by IDL to create the object, JavaClassName is the class name used by Java to initialize the object, and Arg1 through ArgN are any data parameters required by the constructor. See Java Class Names in IDL for more information.

Note: The example hellojava.pro is located in the resource/bridges/import/java/examples directory of the IDL distribution and shows a simple example of an IDL-Java object creation. Run the example procedure by entering hellojava at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT hellojava.pro.

Note: If you edit and recompile a Java class used by IDL during an IDL-Java bridge session, you must first exit and restart IDL before your modified Java class will be recognized by IDL.

The IDL-Java bridge also provides the ability to access static Java methods and data members. See Java Static Access for more information.

Java Class Names in IDL


The underlying Java interpreter recognizes the Java class name including all objects contained within the Java interpreter’s class path.

To identify a proper Java object, the fully-qualified package name should be used when creating the IDL class name. For example, a class of type String would be referred to as java.lang.String.

In the IDL class name, the Java class separator ('.') should be replaced with an underscore ('_'). If a Java class of type String were created, the following IDL OBJ_NEW call would be used:

oJString = OBJ_NEW('IDLJavaObject$JAVA_LANG_STRING', 'java.lang.String', 'My String')

The class name is provided twice because IDL is case-insensitive whereas Java is case-sensitive, see IDL-Java Bridge Architecture for more information.

Note: IDL objects use method names (INIT and CLEANUP) to identify and call object lifecycle methods. As such, these method names should be considered reserved. If an underlying Java object implements a method using either INIT or CLEANUP, those methods will be overridden by the IDL methods and not accessible from IDL. In Java, you can wrap these methods with different named methods to work around this limitation.

Java Static Access


In Java, a program can call a static method or access static data members on a Java class without first having to create the object.

IDL contains a special wrapper object type for calling static methods. This IDL object wrapper references the underlying Java class, allowing the object to call static methods on the class or allowing the object to use the Get/Set Property calls to access static data members. The following line of code demonstrates the basic syntax for calling OBJ_NEW to create a static proxy within IDL:

oJava = OBJ_NEW('IDLjavaObject$Static$JAVACLASSNAME', 'JavaClassName')

where JAVACLASNAME is the class name token used by IDL to create the object and JavaClassName is the class name used by Java to initialize the object. See Java Class Names in IDL for more information.

A special static object would not need to be created to call an instantiated IDLJavaObject with static methods:

oNotStatic = OBJ_NEW('IDLjavaObject$JAVACLASSNAME', 'JavaClassName')
oNotStatic->aStaticMethod ; this is OK

Note: The javaprops.pro file is located in the resource/bridges/import/java/examples directory of the IDL distribution and shows an example of working with static data members. Run the example procedure by entering javaprops at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT javaprops.pro.

Note: All restrictions on creating Java objects apply to this static object.