When the System.loadLibrary()
or System.load()
functions are called, the ClassLoader
for the current Java class is tasked with finding the requested DLL (and its dependencies) and informing the operating system about the libraries' locations. The ClassLoader
itself does not perform any loading: this operation uses the Java Native Interface (JNI) libraries to communicate with the operating system and tells it where to look for the requested libraries.
When a DLL function is called, the function is loaded into the address space of the Java VM process and is executed there. This address space is a memory block given to a process by the operating system and is separate from the Java VM altogether. So, the answer to your question is that the Java VM simply uses its given address space to load DLL functions on-demand and executes them through the Java Native Interface.
Source: http://www.webbasedprogramming.com/Tricks-of-the-Java-Programming-Gurus/ch30.htm