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.


    protected String findLibrary(String lib_name);


  • 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"


// 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);


Library Found: java.lang

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.