Home »
Java programming language
Java ClassLoader findLibrary() method with example
ClassLoader Class findLibrary() method: Here, we are going to learn about the findLibrary() method of ClassLoader Class with its syntax and example.
Submitted by Preeti Jain, on November 28, 2019
ClassLoader Class findLibrary() method
- findLibrary() method is available in java.lang package.
- findLibrary() method is used to find the absolute pathname of the given native library.
- findLibrary() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- findLibrary() method does not throw an exception at the time of returning the absolute path of the given library.
Syntax:
protected String findLibrary(String lib_name);
Parameter(s):
- String lib_name – represents the name of the library.
Return value:
The return type of this method is String, it returns an absolute path of the given library.
Note: It returns null when JVM finds the library along the path given as the system property "java.library.path"
Example:
// Java program to demonstrate the example
// of String findLibrary(String lib_name) method of ClassLoader
class FindLibrary extends ClassLoader {
// Override findLibrary() of ClassLoader
protected String findLibrary(String lib_name) {
if (lib_name.equals("java.lang")) {}
return lib_name;
}
}
public class Main {
public static void main(String[] args) throws Exception {
// Creating an instance of FindLibrary
FindLibrary fl = new FindLibrary();
// we are finding the library java.lang and it returns
// it already exists in Java
String library = fl.findLibrary("java.lang");
System.out.println("Library Found: " + library);
}
}
Output
Library Found: java.lang