易截截图软件、单文件、免安装、纯绿色、仅160KB

C/C++ 与 JAVA 的互操作

前言:前段时间在CSDN的C++社区遇到一个需要封装考勤机接口的动态库给JAVA调用的帖子,勾起了我对JAVA的无限怀念。在此,我想把这项技术简单再介绍一下。
一、关于Java Native Interface (JNI)
JNI是JAVA本地编程接口,属于JDK的一部分。它允许JAVA能够操作本地API或由其他语言编写的动态库。不过当你使用这项技术的时候,需要考虑JAVA的可移植性。
二、编写一个简单的JNI程序
1、编写一个JAVA程序
 
// HelloWorld.java
class HelloWorld
{
//声明本地方法,以native为关键字
public native void displayHelloWorld();
static
{
//加载本地方法所在的动态库
System.loadLibrary("HelloWorld");
}
public static void main(String[] args)
{
new HelloWorld().displayHelloWorld();
}
}
重点部分: a)本地方法以native为关键字声明 b)加载动态库
2、编译源程序
cmd > javac HelloWorld.java
3、创建.h文件我们需要从HelloWorld.class文件中生成对应的.h文件,以便在C/C++编写代码。
cmd>javah -jni HelloWorld
生成的文件(HelloWorld.h)长这个样子:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplusextern "C" {
#endif
/* * Class: HelloWorld * Method: displayHelloWorld * Signature: ()V */
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld (JNIEnv *, jobject);
#ifdef __cplusplus}
#endif
#endif

4、对应HelloWorld.h文件创建一个.c文件,实现部分在里面编写
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
5、编译该.c文件,生成dll
cmd >cl /IC:\j2sdk1.4.2_08\include /IC:\j2sdk1.4.2_08\include\win32 /LD HelloWorld.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
HelloWorld.c
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserve


相关文档:

转载:Hadoop 应该用C++实现,而不是Java

http://www.trendcaller.com/2009/05/hadoop-should-target-cllvm-not-java.html
Sunday, May 10, 2009
Hadoop should target C++/LLVM, not Java (because of watts)
< type="text/javascript">
digg_url="http://www.trendcaller.com/2009/05/hadoop-should-target-cllvm-not-java.html";
Over the years, ......

java中与(&)和或(|)运算

System.out.println(2|0); //0010 0000 =>0010 = 2
System.out.println(2|1); //0010 0001 =>0011 = 3
System.out.println(3|2); //0011 0010 =>0011 = 3
System.out.println(3&2); //0011 0010 =>0010 = 2
/*
  在java中0代表假, 1代表真
  00011|0010  从右到左比较0|1 = 1, 1|0 = ......

java常用正則表達式

public class Regex {

/**
* 检查email输入是否正确
* 正确的书写格式为 username@domain
* @param value
* @return
*/
public boolean checkEmail(String value, int length) {
return value.matches("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)* ......

java集合详解

目    录
1        集合框架... 2
1.1      集合框架概述... 2
1.1.1      容器简介... 2
1.1.2      容器的分类... 4
1.2      Collection. 5
1.2.1  ......

Linux C函数库参考手册

来自一本绝版的书,虽然没有函数
描述,但是最起码可以知道分类,就可以去 man 了
Linux C函数库参考手册
第1章字符测试
函数
isalnum(测试字符是否为英文字母或数字)
isalpha(测试字符是否为英文字母)
isascii(测试字符是否为ASCII码字符)
isblank(测试字符是否为空格字符)
iscntrl(测试字符是否为ASCII码的控制字符 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号