encyclopegia.org

Java Native Access

Java Native Access (JNA) is a community-developed library that provides Java programs easy access to native shared libraries without using the Java Native Interface (JNI). JNA's design aims to provide native access in a natural way with a minimum of effort. Unlike JNI, no boilerplate or generated glue code is required. Since Java 22, the Foreign Function and Memory API was provided as a standard modern alternative.

Java Native Access (JNA) is a community-developed library that provides Java programs easy access to native shared libraries without using the Java Native Interface (JNI). JNA's design aims to provide native access in a natural way with a minimum of effort. Unlike JNI, no boilerplate or generated glue code is required. Since Java 22, the Foreign Function and Memory API was provided as a standard modern alternative. ==Mapping types== The following table shows an overview of types mapping between Java and native code and supported by the JNA library. Note: The meaning of TCHAR changes between char and wchar_t according to some preprocessor definitions. LPCTSTR follows. package org.wikipedia.examples; import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Platform; // Simple example of native library declaration and usage. public class HelloWorld { public interface CLibrary extends Library { CLibrary INSTANCE = (CLibrary) Native.loadLibrary( (Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class); void printf(String format, Object... args); } public static void main(String[] args) { CLibrary.INSTANCE.printf("Hello, World\n"); for (int i = 0; i The following program loads the C POSIX library and uses it to call the standard function. Note: The following code is portable and works the same on POSIX standards platforms. package org.wikipedia.examples; import com.sun.jna.Library; import com.sun.jna.Native; // Simple example of native C POSIX library declaration and usage. public class Example { public interface Posix extends Library { public int chmod(String filename, int mode); public int chown(String filename, int user, int group); public int rename(String oldpath, String newpath); public int kill(int pid, int signal); public int link(String oldpath, String newpath); public int mkdir(String path, int mode); public int rmdir(String path); } public static void main(String[] args) { // It is possible to load msvcrt for its partial POSIX support on Windows... Posix posix = (Posix) Native.loadLibrary("c", Posix.class); // but it will still fail on Windows due to /tmp being missing. posix.mkdir("/tmp/newdir", 0777); posix.rename("/tmp/newdir","/tmp/renamedir"); } } The program below loads the and uses it to call the and functions. Note: The following code works only on Windows platforms. package org.wikipedia.examples; import com.sun.jna.Library; import com.sun.jna.Native; // Simple example of Windows native library declaration and usage. public class Example { public interface Kernel32 extends Library { // FREQUENCY is expressed in hertz and ranges from 37 to 32767 // DURATION is expressed in milliseconds public boolean Beep(int FREQUENCY, int DURATION); public void Sleep(int DURATION); } public static void main(String[] args) { Kernel32 lib = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class); lib.Beep(698, 500); lib.Sleep(500); lib.Beep(698, 500); } } ==See also== JNAerator P/Invoke SWIG ==References== ==External links== Java Native Access Web Page Java Native Access - Download page Java Native Access - User Mailing List

References

No reference rows published for this article.

Cite this article

MLA

"Java Native Access." encyclopegia.org, 2026, https://encyclopegia.org/wiki/java-native-access. Accessed 23 November 2026.

Chicago

"Java Native Access." encyclopegia.org. Accessed November 23, 2026. https://encyclopegia.org/wiki/java-native-access.

APA

encyclopegia.org. (2026). Java Native Access. Retrieved November 23, 2026, from https://encyclopegia.org/wiki/java-native-access

Accessed November 23, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Spoy, Côte-d'Or

enwiki · references available

Campsegret

enwiki · references available

Cantillac

enwiki · references available

Capdrot

enwiki · references available

Carsac-Aillac

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1362591718 · 0.5 · snapshot enwiki-001362591718

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.