Sistema de blogs Diarium
Universidad de Salamanca
Pablo Gallardo's Blog
My professional web log about IT, Cybersecurity & Project Management
 

How to call native code from a Java application

 

 

 

Methods to call a native function

Method 1. Use Runtime class

Runtime class contains the exec method that allows the application to run an operating system command.

An example of how to use this method:

String command = "echo \"Hello World!\"";
Runtime.getRuntime().exec(command);

 

Method 2. Use JNI

Java Native Inteface (JNI) is a foreign function interface that allows code running on JVM to call (or be called by) native applications. Using JNI, one can call methods written in C/C++ or even access assembly language.

 

Method 3. Use JNA

Java Native Access (JNA) is an open source project that makes it possible for you to use native libraries using only Java code, with little to no C programming experience.

 

External references

pmgallardo

About pmgallardo

I studied Computer Science at University of Salamanca. Since then, I have been working first as developer and then as SAP consutant. This blog is about problems I dealt when using computers, and more important, the solutions I found. Whenever I am on an issue and suddenlly I have a flash that leads me to a solution, I document my discoveries in a post.

, , , , , , , , , , , ,

No comments yet.

Leave a Reply


*

Política de privacidad
Studii Salmantini. Campus de excelencia internacional