what are the benefits of java native access ?
Ans:
If a software is designed for a specific platform like windows , then it is always be better to use the native code for creating software.This helps to increase the performance of the system. For example one can call a windows based DLL from a java code.
The JNA API can be downloaded from https://github.com/twall/jna this link.In this library many native code are already mapped with the java functions.There are two jar files associated with this link jna,jar & platform.jar.
Demo
This demo shows how to load kernel32(Windows machine) library to java and shows System time and system detail.
package com.sandeep.jna.demo;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.WinBase.SYSTEMTIME;
import com.sun.jna.platform.win32.WinBase.SYSTEM_INFO;
public class JnaDemo {
public static void main(String[] args) {
Kernel32 INSTANCE = (Kernel32) Native
.loadLibrary("Kernel32", Kernel32.class);
SYSTEMTIME time =new SYSTEMTIME();
INSTANCE.GetSystemTime(time);
System.out.println("Day of the Week "+time.wDayOfWeek);
System.out.println("Year : "+time.wYear);
SYSTEM_INFO systeminfo=new SYSTEM_INFO();
INSTANCE.GetSystemInfo(systeminfo);
System.out.println("Processor Type : "+systeminfo.dwProcessorType);
}
}