Java Native Interface 基于JNI的嵌入式手机软件开发实例
1、通过JNI和c/c++的库组件、其他代码交互
2、java和c不能互通的原因时数据类型问题
Introduction https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/intro.html#java_native_interface_overview
This chapter introduces the Java Native Interface (JNI). The JNI is a native programming interface. It allows Java code that runs inside a Java Virtual Machine (VM) to interoperate with applications and libraries written in other programming languages, such as C, C++, and assembly.
The most important benefit of the JNI is that it imposes no restrictions on the implementation of the underlying Java VM. Therefore, Java VM vendors can add support for the JNI without affecting other parts of the VM. Programmers can write one version of a native application or library and expect it to work with all Java VMs supporting the JNI.
This chapter covers the following topics:
- Java Native Interface Overview
- Historical Background
- Objectives
- Java Native Interface Approach
- Programming to the JNI
- Changes
Java Native Interface Overview
While you can write applications entirely in Java, there are situations where Java alone does not meet the needs of your application. Programmers use the JNI to write Java native methods to handle those situations when an application cannot be written entirely in Java.
The following examples illustrate when you need to use Java native methods:
- The standard Java class library does not support the platform-dependent features needed by the application.
- You already have a library written in another language, and wish to make it accessible to Java code through the JNI.
- You want to implement a small portion of time-critical code in a lower-level language such as assembly.
By programming through the JNI, you can use native methods to:
- Create, inspect, and update Java objects (including arrays and strings).
- Call Java methods.
- Catch and throw exceptions.
- Load classes and obtain class information.
- Perform runtime type checking.
You can also use the JNI with the Invocation API to enable an arbitrary native application to embed the Java VM. This allows programmers to easily make their existing applications Java-enabled without having to link with the VM source code.




JNI_百度百科 https://baike.baidu.com/item/JNI/9412164?fr=aladdin
调用问题
| Java 类型 | 本地 C 类型 |
实际表示的 C 类型
(Win32)
|
说明 |
|---|---|---|---|
| boolean | jboolean | unsigned char | 无符号,8 位 |
| byte | jbyte | signed char | 有符号,8 位 |
| char | jchar | unsigned short | 无符号,16 位 |
| short | jshort | short | 有符号,16 位 |
| int | jint | long | 有符号,32 位 |
| long | jlong | __int64 | 有符号,64 位 |
| float | jfloat | float | 32 位 |
| double | jdouble | double | 64 位 |
| void | void | N/A | N/A |
活动状态
视频捕捉
Java Native Interface 基于JNI的嵌入式手机软件开发实例的更多相关文章
- Java Native Interface Specification(JNI)
Java Native Interface Specification(JNI) 使用场景: 需要的功能,标准的java不能提供 有了一个用其他的语言写好的工具包,希望用java去访问它 当需要高性能 ...
- Java Native Interface 六JNI中的异常
本文是<The Java Native Interface Programmer's Guide and Specification>读书笔记 在这里只讨论调用JNI方法可能会出现的异常, ...
- Java Native Interface 五 JNI里的多线程与JNI方法的注册
本文是<The Java Native Interface Programmer's Guide and Specification>读书笔记 JNI里的多线程 在本地方法里写有关多线程的 ...
- Java Native Interface 四--JNI中引用类型
本文是<The Java Native Interface Programmer's Guide and Specification>读书笔记 JNI支持将类实例和数组类型(如jobjec ...
- Java Native Interface 二 JNI中对Java基本类型和引用类型的处理
本文是<The Java Native Interface Programmer's Guide and Specification>读书笔记 Java编程里会使用到两种类型:基本类型(如 ...
- Java Native Interface(JNI)
JNI能让Java代码在Java虚拟机里调用其他编程语言(例如C.C++)写的应用或库,且不会影响任何Java虚拟机的实现. 什么时候用JNI? 1.应用程序所需的平台相关功能,标准的Java类库不支 ...
- 【详解】JNI (Java Native Interface) (二)
案例二:传递参数给C代码,并从其获取结果 注:这里传递的参数是基本类型的参数,在C代码中有直接的映射类型. 此案例所有生成的所有文件如下: (1)编写案例二的Java代码,如下: 这里我们定义了一个n ...
- Java Native Interface Specification Contents 翻译
https://docs.oracle.com/en/java/javase/12/docs/specs/jni/index.html Google翻译 第1章:简介 本章介绍Java Native ...
- android 学习随笔二十七(JNI:Java Native Interface,JAVA原生接口 )
JNI(Java Native Interface,JAVA原生接口) 使用JNI可以使Java代码和其他语言写的代码(如C/C++代码)进行交互. 问:为什么要进行交互? 首先,Java语言提供的类 ...
随机推荐
- grid响应式布局
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- LabelTTF 设置字体时的问题
使用cc.LabelTTF:create(txt, fontname, fontsize); 字体没能显示出来, 这里使用的是系统字体, 比如我使用"微软雅黑", 作为font ...
- Linux curl 命令下载文件
引用自http://blog.csdn.net/wh211212/article/details/54285921 命令:curl 在Linux中curl是一个利用URL规则在命令行下工作的文件传输工 ...
- osgearth cache
<map name="readymap.org" type="geocentric"> <options> <!--Specify ...
- 原创:Eclipse安装Eclipse Color Themes插件后,编辑器背景颜色被改变
如题,卸载Eclipse Color Themes插件后,背景颜色还是白色,蛋疼,修改.metadata\.plugins\org.eclipse.core.runtime\.settings中的or ...
- 原创:超简单!windows配置NDK开发环境使用JNI
前段时间看android版的opencv的配置教程时,看到了它的NDK配置方法,感觉简单又不会出错!!! 1.下载NDK,设置NDK路径: 在windows的系统环境变量中添加NDK的路径,环境变量名 ...
- PHP 简易导出excel 类解决Excel 打开乱码
<?php class exportCsv{ //列名 protected $_column = array(); protected $_reg = array(); public $ret ...
- Linux下Apache网站目录读写权限的设置
网站目录文件权限的设置对网站的安全至关重要,下面简单介绍网站目录文件权限的基本设定. 我们假设http服务器运行的用户和用户组是www,网站用户为centos,网站根目录是/home/centos/w ...
- php 原生文件下载
1.整个网页的html界面源码下载: xiazai.php <html> <head> <meta charset ="utf-8"> < ...
- WP8.1学习系列(第七章)——应用选项卡Pivot交互UX
“应用选项卡”模式用于用户经常在中间导航的多个 UI 页面.如果你的应用基于单个主题(例如,电影.棒球等),该模式尤其有用.每页都将为用户显示与该应用呈现的整体数据相关的一些内容.“应用选项卡”模式可 ...