Java System.mapLibraryName() – Examples
In this tutorial, we will learn about the Java System.mapLibraryName() function, and learn how to use this function to map name of a library into a platform-specific string representing a native library, with the help of examples.
mapLibraryName(String libname)
System.mapLibraryName() maps a given library name into a platform-specific string representing a native library.
mapLibraryName(libname) throws java.lang.NullPointerException
if libname
is null
.
Syntax
The syntax of mapLibraryName() function is
mapLibraryName(String libname)
where
Parameter | Description |
---|---|
libname | The name of library. |
Returns
The function returns String representing a platform-dependent native library name.
Example 1 – mapLibraryName(libname)
In this example, we will give login
as library name to System.mapLibraryName() method. The method returns login.dll
which is platform-dependent native library name.
Java Program
public class Example {
public static void main(String args[]) {
String libname = "login";
String nativeLibname = System.mapLibraryName(libname);
System.out.println(nativeLibname);
}
}
Output
login.dll
Example 2 – mapLibraryName(libname) – Null libname
In this example, we will pass null
value to mapLibraryName() method. For a null argument, mapLibraryName() throws java.lang.NullPointerException
.
Java Program
public class Example {
public static void main(String args[]) {
String libname = null;
String nativeLibname = System.mapLibraryName(libname);
System.out.println(nativeLibname);
}
}
Output
Exception in thread "main" java.lang.NullPointerException
at java.base/java.lang.System.mapLibraryName(Native Method)
at Example.main(Example.java:4)
Conclusion
In this Java Tutorial, we have learnt the syntax of Java System.mapLibraryName() function, and also learnt how to use this function with the help of examples.