JiGlue Java - COM Data Types

This topic describes the Java - COM data type conversions between primitive and reference Java data types and COM data types supported by the JiGlue COM Bridge.

Topics include:

JiGlue COM Bridge Java-to-COM Data Type Conversions

The JiGlue COM Bridge supports the following Java to COM data type conversions:

Note Reference (non-primitive) Java data types, such as one-dimensional and multi-dimensional arrays and other Java objects, are also supported (see JiGlue COM Bridge Programming Guidelines below).

Caution If you are coding in Visual Basic, remember that in VB an integer (int) is a 16-bit value, whereas in Java, int is a 32-bit two's complement value; for details, see JiGlue COM Bridge Programming Guidelines below.

Java Data Type

COM Data Type

Data Type
Description Size/Structure
Data Type (VT_)

boolean (java.lang.Boolean)

Boolean value true or false

Boolean (VT_I1)

char (java.lang.Char) A single character 16-bit single Unicode character
2-byte unsigned (VT_UI2)
short (java.lang.Short) Short integer 16-bit two's complement
2-byte signed integer (VT_I2)

int (java.lang.Integer)

Integer 32-bit two's complement

4-byte signed integer (VT_I4)

long (java.lang.Long) Long integer 64-bit two's complement
4-byte signed integer (VT_I4)*

float (java.lang.Float)

Single-precision floating point 32-bit IEEE 754

Float (VT_R4)

double (java.lang.Double) Double-precision floating point 64-bit IEEE 754
Double (VT_R8)

java.lang.String

Text string. String

BSTR (VT_BSTR)

java.util.Date Date Date
Date (VT_DATE)

Other Java object

Reference Reference

IDispatch (VT_DISPATCH)

*Conversion of a Java Long integer (long) to a COM 4-byte signed integer (VT_I4) may result in a loss of precision, due to the conversion from a 64-bit value to a 32-bit value.

JiGlue COM Bridge Programming Guidelines

The following guidelines should be kept in mind when coding an application using the JiGlue COM Bridge:

However, if a Java method returns an object other than the java.lang.* (see below), the Set statement is needed.

Example 2:

Dim myDate As Variant
Dim mySimpleDate As Variant
Set mySimpleDate = JiGlue.newInstance("java.text.SimpleDateFormat")
myDate = mySimpleDate.parse("09/12/2001 11:59 am")

In the examples shown above, mySimpleDate was declared as both Object and Variant (in the different examples); in both cases, the object reference was assigned by using Set. Notice that in both cases myDate was declared as Variant without using the Set statement. The reason this works as coded, is because a SimpleDateFormat.parse returns java.util.Date which is mapped to Visual Basic's Date type (which is non-object — see table above). As previously indicated, if a Java method returns an object other than the java.lang.* (as indicated above), the Set statement is needed. Note that the Jiglue.newInstance method can only instantiate an object whose class has a default constructor; that is, without any argument (see previous bullet).