![]() |
VOOZH | about |
In Java Programming Langauge the Runtime class mainly allows us to interact with the runtime environment of our application. There is one of the important method load() provided by this Runtime class which allows Java applications to dynamically load the libraries into the Java environment. In this article, we will see the detailed overview, syntax, and example of Java Runtime load() Method.
The Java Runtime load() Method in the Runtime class is mainly used to load the specified filename as a dynamic library into our Java environment application. This method only accepts the library name in terms of complete path names as input and allows that tile to be loaded into the application. There is no return type value for this function as it is operated as a void function.
public void load(String filename)
Examples of using the runtime objects are mentioned below:
Using the Java Runtime method load() we will try to load a system file.
Below is a demonstration of how to Load a Library:
Library Loaded.
LoadMethod with a main function.apds.dll library located in the folder using the Runtime.getRuntime().load(String filename) method.Using the Java Runtime method load() we will try to load a file present at a custom path location.
Below is the implementation of how to Load a file from a Custom location:
Library Loaded.
SampleRes.dll located in the folder.Runtime.load() method and a try-catch block.Using the Java Runtime method load() we will try to load a file present at a non-existing location
Below is the implementation of loading a non-existent library:
Failed to load library. Error: Can't load library: C:/Error/nonexist.dll
nonexist.dll located in the non-existent path C:/Errortry-catch block to handle any potential errors.UnsatisfiedLinkError that occurs during the loading process.To handle exceptions for the load() method of Java Runtime, we have these:
The Runtime.load() method provides the process for dynamically loading the native libraries into the Java application. It allows the proper loading of existing files and also provides the Exception when a non-existent file is attempted to be loaded in the application. This method is efficient integration of libraries into our native application code.