Bridges > Java Import Bridge > Overview Of Using Java Objects

# Overview Of Using Java Objects

Java is an object-oriented programming language developed by Sun Microsystems that is commonly used for web development and other programming needs. It is beyond the scope of this chapter to describe Java in detail. Numerous third-party books and electronic resources are available. The Java website (http://java.sun.com) may be useful.

The IDL-Java bridge allows you to access Java objects within IDL code. Java objects imported into IDL behave like normal IDL objects. See Creating IDL-Java Objects for more information. The IDL-Java bridge allows the arrow operator (->) to be used to call the methods of these Java objects just as with other IDL objects, see Method Calls on IDL-Java Objects for more information. The public data members of a Java object are accessed through GetProperty and SetProperty methods, see Managing IDL-Java Object Properties for more information. These objects can also be destroyed with the OBJ_DESTROY routine, see Destroying IDL-Java Objects for more information.

Note: IDL requires an evaluation or permanent IDL license to use this functionality. This functionality is not available in demo mode.

The bridge also provides IDL with access to exceptions created by the underlying Java object. This access is provided by the IDLJavaBridgeSession object, which is a Java object that maintains exceptions (errors) during a Java session, see The IDLJavaBridgeSession Object for more information.

Note: Visual Java objects cannot be embedded into IDL widgets.

Note: On Solaris, there are potential problems creating graphical windows from the IDL-Java bridge using Java versions before 1.5. We recommend using the XToolkit option, which the IDL-Java bridge will use by default.

## Java Runtime Environment Requirements

IDL supports version 1.7 and greater of the Java runtime environment.

Note: On Macintosh machines, the version of Java installed along with the operating system should be sufficient, whatever its version number.

## Java Terminology

You should become familiar with the following terms before trying to understand how IDL works with Java objects:

Java Virtual Machine (JVM) - A software execution engine for executing the byte codes in Java class files on a microprocessor.

Java Native Interface (JNI) - Standard programming interface for accessing Java native methods and embedding the JVM into native applications. For example, JNI may be used to call C/C++ functionality from Java or JNI can be used to call Java from C/C++ programs.

Java Invocation API - An API by which one embeds the Java Virtual Machine into your native application by linking the native application with the JVM shared library.

Java Reflection API - Provides a small, type-safe, and secure API that supports introspection about the classes and objects. The API can be used to:

- Construct new class instances and new arrays
- Access and modify fields of objects and classes
- Invoke methods on objects and classes
- Access and modify elements of arrays

## IDL-Java Bridge Architecture

The IDL-Java bridge uses the Java Native Interface (JNI), the reflection API, and the JVM to enable the connection between IDL and the underlying Java system.

The IDL OBJ_NEW function can be used to create a Java object. A Java-specific class token identifies the Java class used to create a Java proxy object. IDL parses this class name and creates the desired object within the underlying Java environment.

The Java-specific token is a case-insensitive form of the name of the Java class. Besides the token, the case-sensitive form of the name of the Java class is provided because Java itself is case-sensitive while IDL is not. IDL uses the case-insensitive form to create the object definition while Java uses the case-sensitive form.

After creation, the object can then be used and manipulated just like any other IDL object. Method calls are the same as any other IDL object, but they are vectored off to an IDL Java system, which will call the appropriate Java method using JNI.

The OBJ_DESTROY procedure in IDL is used to destroy the object. This process releases the internal Java object and frees any resources associated with it.