System.mapLibraryName() in Java

System.mapLibraryName(): This method is available in java.lang.System class of Java.

Syntax:

String java.lang.System.mapLibraryName(String libname)

This method takes one argument of type String as its parameter. This method maps a library name into a platform-specific string representing a native library.

Parameters: One parameter is required for this method.

libname: the name of the library.

Returns:platform-dependent native library name.

Throws:

NullPointerException - if libname is null.

Approach

Java

public class SystemmapLibraryName {
    public static void main(String[] args) {

        String libname = "os.name";
        System.out.println(System.mapLibraryName(libname));
    }
}

Output:

os.name.dll


Approach 2: NullPointerException 

Java

public class SystemmapLibraryName {
    public static void main(String[] args) {

        String libname = null;
        System.out.println(System.mapLibraryName(libname));
    }
}


Output:

Exception in thread "main" java.lang.NullPointerException at java.base/java.lang.System.mapLibraryName(Native Method)


No comments:

Post a Comment