Javonet is a Runtime Bridging technology that allows to use libraries created in .NET directly from Java and vice versa. Javonet is packed as single Jar file that can be added to any Web, Desktop, Service, HMI, SCADA, workflows or other project. Development teams by adding Javonet to their project get immediate unrestricted access to those two technologies.

Difference between .NET and Java runtimes?

Both programming frameworks use utilize virtual machines to translate intermediate code to machine code. The program is first compiled to the managed code which is understood by the CLR (Common Language Runtime) in .NET and Hotspot (Java Virtual Machine) in Java. Both Java Virtual Machine and Common Language Runtime are the runtimes which manage the code that they have received (garbage collection, memory allocation). The managed code during execution is translated to the machine code. Biggest difference in runtimes is .NET code is optimized in compile time and Java Hotspot can optimize instructions “at runtime”.

The diagrams below shows what happens when the code is complied and executed in both Java and .NET.

What is Runtime Bridging?

In case when we face the need to use the already compiled libraries (assemblies) which were compiled for Java from .NET (or vice versa) it is not possible to do it out of a box with the existing platforms. Java compiled code is prepared for Java Virtual Machine and is not understandable by the .NET’s Common Language Runtime and the same .NET’s compiled code is prepared for CLR (Common Language Runtime) but not understandable by the JVM.

With Javonet you can take any compiled code from Java and use it from .NET and vice versa. It is done by Runtime Bridging. This means that the code of Java is still executed by JVM and the code of .NET to be executed by .NET CLR and Javonet takes care of reliable and safe communicating the both runtimes.

So if we use the .NET dll from Java application with Javonet which can be called the Java and .NET integration, the Java code which references the .NET dll is executed by JVM and if any of the methods from .NET library are called they are executed by the Common Language Runtime. This is the job of Javonet to integrate both so that all happens with the native performance, full safety and ultimately quickly.

The whole communication is done in a single OS process which guarantees the highest performance as there is no impact on the communication. The two Runtimes work next to each other in the single OS process and each is responsible for the part of the code which is developed for it’s platform.

The advantage of Runtime Bridging ready to use solutions is that first we obtain the possibility to use the libraries cross-platform, second we do not need to maintain any of custom solutions for integrating Java and .NET, third Java and .NET become as one which results in no need of rewriting the code or maintain two separate code bases (Java code base and .NET code base).

How is it done?

To learn how it is possible we need to understand more concepts how machine and manage code works.

What is machine code?

The high-level programming language that the developer uses to write the code (i.e. Java language or C#) is well understood by the developer but completely foreign to the computer. This is reasonable as the high-level language is far from the sequences of zeros and ones which are coming to the processor as the instructions which at the end translate to electric current flowing or not flowing, when a computer program is executed.

The language understood by the machines is called the machine code and it is a numerical lowest-level code which is obtained by compiling the high-level code to the intermediate code (Common Intermediate Language for .NET and Java Bytecode for Java) and then to the machine code (01101101 01100001 01100011 01101000 01101001 01101110 01100101 00100000 01100011 01101111 01100100 01100101). The zeros and ones in the brackets represent the word “machine code” in the binary format.

As the machine code needs to be specific for different computer architectures, the idea of the executable code and a runtime environment has been developed in order to allow the multiple different high-level languages to be used for software development without a need to care about the specific environment (computer architecture) the software will then be executed in. Other words this allows for the high-level programming languages to be platform agnostic.

What is managed code?

The high-level programming language is compiled to the Common Intermediate Language (.NET) which can be understood by Common Language Runtime in .NET or to Java Bytecode which can be understood by JVM in Java. The Runtime is taking care of executing and managing the code which assumes services such as security, memory management, threading, and the like..

Already existing interoperability

In fact there is a level of interoperability that already exists in Java and .NET. This kind of interoperability assumes the possibility of using many different languages for the particular framework. However there are the languages created for .NET which means that they can be compiled to the Common Intermediate Language (C#, F#, J#, Visual Basic) and there are the languages for JVM (Java, Groovy, Scala, R) but they do not mix with each other as they are executed by different runtimes. There is also built-in foreign function interface to call the native code like C++ both from .NET and Java.

However this kind of interoperability would allow us to chose the different programming languages from the range available for the particular platform only and interact with native code. No cross-platform mixing would be possible.

Where is Javonet used?

There are many cases when it becomes necessary to use the library from other platform.

Devices SDKs

There are the devices which do not provide the SDKs for some of the platforms and there is a need use the external .NET libraries from Java or vice versa.

Examples:

Oil drilling sensors

Healthcare devices (respiration devices, measuring devices)

Assembly line quality check devices

Point Of Sales devices

Payment processing devices

Manufacturing devices

Robotic assembly solutions

Back-end components

There are the scenarios where the ready big Java based crucial systems out of a sudden need to implement the functionality which comes only as the .NET dlls.

The IVR systems

Database drivers

External algorithms

SCADA systems data exchange modules

UI Controls

There are the UI controls which were targeted to single platform but they are excellente for particular usage.