Basic tutorial on IVKM and Java in .NET
Okay, a quick overview of the lifecycle from a Java .java file to a .NET .dll and consuming it in a .NET application. The team working on IVKM is simply brilliant—this was great!
Step #1 – Creating the Java source file.
Let’s say I have a simple Employee class in Java (screenshots are in Eclipse, your Java editor may vary). Three simply properties and overriding the toString method to provide a nice, clean output.
Step #2 – Converting the Java class to a .NET Library.
After you’ve compiled, Eclipse (or javac) will generate a .class file out of your .java file. This is usually located in your bin\%packageName% directory.
To compile the .class file to a .dll, use the IKVMC executable.
Step #3 – Using the new .NET Library in a project.
Create or open a project and add a reference to your new library. It should also add in the two IVMK libraries—GNU.Classpath and Runtime.
You’ll also need to add a using statement. The using namespace will simply be the name of the package in Java. I this case, it’s TiredStudent.
Using the Employee object is as simple as it would be in .NET. A few properties and then using the toString() (lowercase to in Java) to output the results to the web.
You’ll note that this is a very simplistic class; however, it’s excellent to see that work that goes into some of these Java projects (and in our organization’s case, upcoming Java projects) can be reused within the .NET environment—without redesigning/recoding existing logic.
Very cool and, thanks to open source—very free!
Note: As a side note, an odd finding. Screen captures of Console (a sweet freeware command prompt I use for working with shell and PowerShell stuff) won’t show up unless you turn Alpha transparency off. *sigh*