The Basics of accessing Java using EZ JComThis page covers some basic information that should be learned for using EZ JCom to access Java from languages such as C# and VB.
Adding the COM (ActiveX) DLL generated by EZ JCom to your projectEZ JCom will generate a COM DLL that provides access to the Java classes. This DLL needs to be added to your Visual Basic or C# (or other language) project. Typically, there is an "Add Reference" menu item for the project. In some cases, the "Add Reference" menu item has multiple tabs, in such cases, select the "COM" tab.
Once a reference has been added to the project, Intellisense will show the new library and its contents.
ConstructorsIn Java, there can be multiple constructors for constructing an object. Since EZ JCom supports multiple languages via COM, the "new" operation in EZ JCom doesn't take parameters. Instead, when accessing Java via EZ JCom, one of the constructors must be called after instantiating a "new" object, and before accessing any methods or fields.
There are two exceptions -- for accessing "static" methods or fields of Java, a constructor does not have to be called. And for event objects in use for receiving Java events, a constructor does not have to be called.
How do I pass this object of class A that implements/extends class B, where the method I am calling only expects class B?EZ JCom does not attempt to map the Java class and interface hierarchies in COM. Instead, Java casting is handled by a special type of constructor named ConstuctByCasting. When you use ConstructByCasting, you are sharing the underlying Java object, and are creating multiple COM objects of different types that refer to the same Java object.
This allows you to cast a C# or VB or other COM object that corresponds to a Java object into another type that corresponds to a Java superclass/subclass of the original Java object, or to a Java interface that's been implemented by the original object. By using this mechanism, all kinds of Java hierarchies can be handled in all COM supporting languages.
For instance, if method MyMethod expects a parameter of type java.security.Principal (a Java interface) and you have another type MySecurityPrincipal that implements java.security.Principal, the code for passing this parameter may look like this:
// Construct the actual parameter MySecurityPrincipal msp = new MySecurityPrincipal(); msp.Construct(); // Instantiate a "wrapper" and use ConstructByCasting // to share the underlying Java object as a different COM type. Principal p = new Principal(); p.ConstructByPasting( msp ); // Pass the wrapper as parameter. myObj.MyMethod( p );
ClasspathThe Java classes must be available in the classpath at runtime. There are a few different mechanisms available:
OtherSome other features that you should be aware of that EZ JCom provides: