Rutgers University Excellence Campaign 2/20/2004 Java Native Interface Tutorial Xiaolin Li Rutgers.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Inlining Java Native Calls at Runtime (CASCON 2005 – 4 th Workshop on Compiler Driven Performance) Levon Stepanian, Angela Demke Brown Computer Systems.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
More Specifically JNI Justin Catterson.  ADA  C++  Java  Ruby  Python  Haskell  Perl  etc. What is a Foreign Function Interface? Simply an interface.
Java Native Interface Modified from CS587x Lecture Department of Computer Science Iowa State University.
Writing Native Code for Android Systems. Why ndk There exist large c++ code libraries – E.g., Audio and video compression, e.g., Ogg Vorbis, The LAME.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
I Dream of JNI When it absolutely, positively has to be written in COBOL... shudder.
mbe/pa/olm 1 Integration of BETA with Eclipse eTX presentation Barcelona 2004 Peter Andersen Mads Brøgger Enevoldsen Ole Lehrmann Madsen.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Administrivia No class next Monday (May 2) Enjoy extra time on P3. ;-) Reading 3 available “Reflections on Trusting Trust”, Ken Thompson No written summary.
Java Native Interface (JNI). JNI Linking Java and C code.
C Primer CAS CS210 Ying Ye Boston University. Outline Hello, world Basics in C Comparison of C and Java.
SEEM3460 Tutorial Java Programming in Unix. Code Translation Java source code Java bytecode Java compiler Bytecode interpreter machine code for target.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
CSC3170 Introduction to Database Systems
Java Programming Robert Chatley William Lee
Java Native Interface CS587x Lecture Department of Computer Science Iowa State University.
What is Android NDK ● A toolset that lets you embed in you app native source code ● C, C++(recently supported December 2010) and assembly(?) ● It is supported.
CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday.
FRST JAVA PROGRAM. Getting Started with Java Programming A Simple Java Application Compiling Programs Executing Applications.
Java Introduction to JNI Prepared by Humaira Siddiqui.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Java Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
Android JNI and JAR Library JNI Library 1. JNI *.c sources file must include jni header file jni.h #include 2. In Make file CFLAGS must add -I $(NDK_INC)/
Programming in java Lecture-2 Java Introduction. Platform Computing platform include hardware and software framework, this combination allows software.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and web applications Very rich GUI libraries Portability (machine independence) A real Object.
A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
12/8/2015\course\cpeg323-07Fs\Topic2b-323.ppt1 Topic 2b High-Level languages and System Software (Languages) Introduction to Computer Systems Engineering.
Overview of Java CSCI 392 Day One. Running C code vs Java code C Source Code C Compiler Object File (machine code) Library Files Linker Executable File.
Slide Advanced Programming 2004, based on LY Stefanus's slides Native Methods.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
From C++ to Java SNU iDB Lab. Hyoung-woo Park March 26, 2007.
introductory lecture on java programming
DISTRIBUTED OBJECTS AND REMOTE INVOCATION 1. 2 Topics  Middleware  Remote Method Invocation  Remote Procedure Call.
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
Christian Wagner Re-Modeling of complex software systems STRESS 2006 ( ) Dortmund Christian Wagner.
Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
C is a high level language (HLL)
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
CS-140 Dick Steflik Lecture 3. Java C++ Interpreted optimized for the internet Runs on virtual ized machine Derived from C++ Good object model Widely.
Introduction of Java Fikri Fadlillah, S.T.
Java Native Interface (JNI)
Eclipse.
Interface.
Introduction to.
Internet and Java Foundations, Programming and Practice
Ch 1. A Python Q&A Session Bernard Chen 2007.
CSE 351 Section 1: HW 0 + Intro to C
An Introduction to Java – Part I, language basics
Java Intro.
CS 180 Assignment 6 Arrays.
class PrintOnetoTen { public static void main(String args[]) {
CS 584 Lecture 18 Assignment Glenda assignment extended to the Java RMI Deadline No Java RMI Assignment Test Friday, Saturday, Monday.
Debugging Exercise 00 Try compiling the code samples.
F II 2. Simple Java Programs Objectives
Compile and run c files.
Presentation transcript:

Rutgers University Excellence Campaign 2/20/2004 Java Native Interface Tutorial Xiaolin Li Rutgers

2 Rutgers University Excellence Campaign Motivation A seamless bridge between Java and native implementation in C, C++ or other languages Java Application and Library JVM JNI Native Application And Library Host Environment (OS)

3 Rutgers University Excellence Campaign Getting Started 1. Create a Java class that declares the native method Hello.java 2. Compile (javac) Hello.class 3. Javah –jni Hello Hello.h 4. Write C impl Hello.c 5. Compile C code and generate native lib Hello.dll or libhello.so 6. Done Run the java application Java Hello

4 Rutgers University Excellence Campaign Hello World // Hello.java public class Hello { static { String libpath = System.getProperty("java.library.path"); libpath += ":."; System.setProperty("java.library.path", libpath); System.loadLibrary("Hello"); } public static void main(String[] args) { Hello hello = new Hello(); hello.Hello(); } private native void Hello(); }

5 Rutgers University Excellence Campaign Hello World // Hello.c #include #include "Hello.h" JNIEXPORT void JNICALL Java_Hello_hello(JNIEnv* env, jobject obj) { printf("Hello, World.\n"); }

6 Rutgers University Excellence Campaign Executable Java Application int main(int argc, char * argv[]) { JNIEnv *env; JavaVM *jvm; jint res; jclass cls; jmethodID mid; // 1. create JVM res = JNI_CreateJavaVM(&jvm, (void**) &env, &vm_args); // 2. find and load the Java application cls = (*env)->FindClass(env, "Hello"); mid = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String;)V"); // 3. execute it (*env)->CallStaticVoidMethod(env, cls, mid, args); (*jvm)->DestroyJavaVM(jvm); }

Rutgers University Excellence Campaign 2/20/2004 Thank You