EZ Jcom
Java-COM JNI Bridge

EZ Jcom "Calling Java" Tutorial:  Step one

This tutorial covers calling Java from the following languages:
  • C#
  • Visual Basic 6
  • Visual Basic .NET

The EZ JCom installation includes a Java JAR file

for use in this tutorial. This JAR file contains a very small number of Java classes and interfaces containing very simple methods, that show the concepts for using EZ JCom to call Java from other languages. The first step of the tutorial is to gain brief familiarity with the contents of this JAR file.

The Java classes and interfaces provided in this JAR file are briefly described below. This tutorial assumes that the reader may not know Java, therefore if you do know Java you may find some information superficial!


This Java class provides
  • A method reverse that reverses a string,
  • A method getRandomSeed that provides a "seed" number for random number generation, and
  • A static Java method getTime that returns the current date and time. (Calling static methods does not require an object to be constructed first.)
This class implements the interface tutorial.ReverseString. This means objects of this class tutorial.CallingJavaTut can be passed as argument to any method that is expecting an argument of type tutorial.ReverseString.


This is a Java interface. It has one method reverse that reverses a string. It does not contain an implementation of reverse as it is an interface. As mentioned above, the tutorial.CallingJavaTut class contains an implementation of reverse.


This class extends the class tutorial.CallingJavaTut. Extending a class in Java means that wherever an argument of type tutorial.CallingJavaTut is expected, tutorial.CallingJava2 may be substituted. Also, this class automatically gets the methods and fields of CallingJavaTut. It provides two additional methods:
  • factorial It returns the integer factorial of an integer number.
  • testException Calling this method generates a null-pointer exception with a stack-trace, for demonstration of Java stack-traces.


In Java, events are handled via interfaces. The tutorial.OnTimer interface handles timer events. It contains only one method onTime which takes a date and time value as argument.


This class contains various methods that show how to handle Java "casting" in EZ JCom.
  • revConcat Takes two strings, and an object that implements tutorial.ReverseString interface, as arguments. Reverses both strings and concats them and returns the result.
  • startTimer Starts timer events. Takes two arguments. First argument is an OnTimer interface to receive ("listen" to) the timer events. Second argument is the number of seconds between events. Only one listener interface can be handled by this class. (Though typical Java event sources can usually handle multiple listeners, as this is a tutorial, this class is somewhat simplified.)
  • stopTimer Stops timer events.
  • initRandom Initializes random number generation. Takes an argument of type tutorial.CallingJavaTut.
  • getRandom Returns a random number.


This class extends a Swing JPanel and builds a simple user interface including checkboxes, radio-boxes, and a JButton. In addition to a constructor, this class has a method to register a listener for the JButton button-clicks. For this Java class, EZ JCom can optionally generate a visual control that can be embedded in C#, VB6 or VB.NET forms.


An interface for listening to button-click events in tutorial.UITut objects.
Now we will proceed to buiding a COM (ActiveX) wrapper for these Java classes, so the methods can be called from other languages.

Next Step: Building the bridge