<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jni | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/jni-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Sat, 10 Dec 2022 05:20:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>JNI Part 5: JNI Arrays</title>
		<link>https://studentprojects.in/software-development/jni/jni-tutorial/jni-part-5-jni-arrays/</link>
					<comments>https://studentprojects.in/software-development/jni/jni-tutorial/jni-part-5-jni-arrays/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Mon, 22 Aug 2011 04:48:41 +0000</pubDate>
				<category><![CDATA[JNI Tutorial]]></category>
		<category><![CDATA[jchararray]]></category>
		<category><![CDATA[jintarray]]></category>
		<category><![CDATA[ReleaseIntArrayElements]]></category>
		<category><![CDATA[SetIntArrayRegion]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[jni]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1688</guid>

					<description><![CDATA[<p>Arrays have dimension. An array’s dimension determines the number of indexes needed to access an element. The standard convention for declaring arrays is: String[] s; // one-dimensional array String s[]; // one-dimensional array String[][] s; // two-dimensional array Declaring the size of the array with the following notation is illegal: String[5] s; // illegal declaration</p>
<p>The post <a href="https://studentprojects.in/software-development/jni/jni-tutorial/jni-part-5-jni-arrays/">JNI Part 5: JNI Arrays</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<ol>
<li>Arrays have dimension. An array’s dimension determines the number of indexes needed to access an element.</li>
<li>The standard convention for declaring arrays is:
<ul>
<li>String[] s; // one-dimensional array</li>
<li>String s[]; // one-dimensional array</li>
<li>String[][] s; // two-dimensional array</li>
</ul>
</li>
<li>Declaring the size of the array with the following notation is illegal:
<ul>
<li>String[5] s; // illegal declaration</li>
</ul>
</li>
<li>An array implicitly extends java.lang.Object. Therefore, an array is an instance of Object class. Hence, arrays in Java are objects.</li>
<li>Declaring an array does not create an array object or allocate space in memory; it creates a variable with a reference to an array.</li>
<li>Since arrays are Objects they can be initialized using the new operator.</li>
<li>When created, arrays are automatically initialized with the default value of their type.
<ul>
<li>String[] s = new String[100];   // default values: null</li>
<li>boolean[] b = new boolean[4]; // default values: false</li>
<li>int[][] i = new int[10][10];        // default values: 0</li>
</ul>
</li>
<li>The JNI treats primitive arrays and object arrays differently.</li>
<li>Primitive arrays contain elements that are of primitive types such as int and boolean.</li>
<li>Object arrays contain elements that are of reference types such as class instances and other arrays.
<ul>
<li>int[] iarr;</li>
<li>float[] farr;</li>
<li>Object[] oarr;</li>
<li>int[][] arr2;</li>
</ul>
</li>
<li>Accessing primitive arrays in a native method requires the use of JNI functions similar to those used for accessing strings.</li>
<li>The JNI Get&lt;Type&gt;ArrayRegion function copies all the elements in the JNI array into a C buffer of an appropriate type. The second argument is the starting index of the elements, and the third argument is the number of elements to be copied. Once the elements are in the C buffer, we can access them in native code.
<ul>
<li>Example: env-&gt;GetCharArrayRegion(arr, 0, arrLength, chArrRWB);</li>
</ul>
</li>
<li>The JNI also supports a corresponding Set&lt;Type&gt;ArrayRegion function that allows native code to modify the array elements. Arrays of all the primitive types (such as boolean, short, and float) are also supported.</li>
<li>The JNI supports a family of Get/Release&lt;Type&gt;ArrayElements functions (for example, Get/ReleaseIntArrayElements) that allow the native code to obtain a direct pointer to the elements of primitive arrays.</li>
<li>The GetArrayLength function returns the number of elements in primitive or object arrays.</li>
</ol>
<p><strong>Example: Accessing intarray</strong></p>
<pre lang="c" line="1" escaped="true">JNIExport jint JNICALL Java_IntArray_sumArray(JNIEnv *env, jobject obj,
	jintArray arr){
		jsize len = *env-&gt;GetArrayLength(env,arr);
		jint *body = *env-&gt;GetIntArrayElements(env,arr,0);
		for (jint i = 0; i &lt; len; ++i){
			sum += body[i];
		}
	*env-&gt;ReleastIntArrayElements(env, arr, body, 0);
}</pre>
<table class="tbl" border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="30%"><strong>JNI Function</strong></td>
<td width="70%"><strong>Description</strong></td>
</tr>
<tr>
<td>Get&lt;Type&gt;ArrayRegion<br />
Set&lt;Type&gt;ArrayRegion</td>
<td>Copies the contents of primitive arrays to or from a pre-allocated C buffer.</td>
</tr>
<tr>
<td>Get&lt;Type&gt;ArrayElements<br />
Release&lt;Type&gt;ArrayElements</td>
<td>Obtains a pointer to the contents of a primitive array. May return a copy of the array.</td>
</tr>
<tr>
<td>GetArrayLength</td>
<td>Returns the number of elements in the array.</td>
</tr>
<tr>
<td>New&lt;Type&gt;Array</td>
<td>Creates an array with the given length.</td>
</tr>
<tr>
<td>GetPrimitiveArrayCritical<br />
ReleasePrimitiveArrayCritical</td>
<td>Obtains or releases a pointer to the contents of a primitive array. These functions allow virtual machines to disable garbage collection while the native code accesses the contents of primitive arrays.</td>
</tr>
</tbody>
</table>
<p><strong>JNI Array Example program</strong></p>
<p>Let’s write a JNI application that passes an unsorted integer array to a native method, which method sorts and sends it back to the application.</p>
<p>The Java code will be(SortArray.java):</p>
<pre lang="java" line="1" escaped="true">class SortArray {
	private native int[] sort(int[] arr);  //native method 

	static   //static initializer code
	{
		System.loadLibrary("SortArray");
	} 

	public static void main(String[] args)
	{
		int iArr[] = {4,5,2,7,1,9}; // Input array
		int oArr[]; //Output array

		SortArray arr = new SortArray();

		System.out.println("Unsorted array: ");
		for(int i = 0; i &lt; iArr.length; i++){
			System.out.println(iArr[i] + " ");
		}

		oArr = arr.sort(iArr);

		System.out.println("Sorted array: ");
		for(int i = 0; i &lt; oArr.length; i++){
			System.out.println(oArr[i] + " ");
		}
	}
}</pre>
<p>Compile SortArray.java (javac SortArray.java) and generate hedder file(javah -jni SortArray).</p>
<p>The generated with javah header file SortArray.h will be:</p>
<pre lang="c" line="1" escaped="true">/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class SortArray */

#ifndef _Included_SortArray
#define _Included_SortArray
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     SortArray
 * Method:    sort
 * Signature: ([I)[I
 */
JNIEXPORT jintArray JNICALL Java_SortArray_sort
  (JNIEnv *, jobject, jintArray);

#ifdef __cplusplus
}
#endif
#endif</pre>
<p>The C++ implementation file SortArray.cpp will be:</p>
<pre lang="cpp" line="1" escaped="true">#include "SortArray.h"
#include "jni.h"

/*
 * Class:     SortArray
 * Method:    sort
 * Signature: ([I)[I
 */
JNIEXPORT jintArray JNICALL Java_SortArray_sort
    (JNIEnv *env, jobject obj, jintArray arr){

    jsize arrLength = env-&gt;GetArrayLength(arr);
    jintArray arrSorted = env-&gt;NewIntArray(arrLength); 

    jint *arrOut = NULL;
    arrOut = env-&gt;GetIntArrayElements(arr, 0);

    for(jsize x = 0; x &lt; arrLength; x++){
        for(jsize y = 0; y &lt; arrLength - 1; y++){
                        if(arrOut[y] &gt; arrOut[y+1]){
				jsize temp = arrOut[y+1];
				arrOut[y+1] = arrOut[y];
				arrOut[y] = temp;
			}
		}
	}

    env-&gt;SetIntArrayRegion(arrSorted, 0, arrLength, arrOut);
    env-&gt;ReleaseIntArrayElements(arr, arrOut, 0);

    return arrSorted;
}</pre>
<p>Run the program (java SortArray) and verify the output.</p><p>The post <a href="https://studentprojects.in/software-development/jni/jni-tutorial/jni-part-5-jni-arrays/">JNI Part 5: JNI Arrays</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/jni/jni-tutorial/jni-part-5-jni-arrays/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>JNI Part 3: Passing Arguments and Mapping Types</title>
		<link>https://studentprojects.in/software-development/jni/jni-tutorial/jni-part-3-mapping-types-passing-arguments/</link>
					<comments>https://studentprojects.in/software-development/jni/jni-tutorial/jni-part-3-mapping-types-passing-arguments/#respond</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Mon, 22 Aug 2011 04:42:39 +0000</pubDate>
				<category><![CDATA[JNI Tutorial]]></category>
		<category><![CDATA[mapping types]]></category>
		<category><![CDATA[object types]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[primitive]]></category>
		<category><![CDATA[jni]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1664</guid>

					<description><![CDATA[<p>The implemented JNI native methods have two standard parameters, in addition to the arguments declared in their Java-side declaration. The first parameter, the JNIEnv interface pointer, points to a location that contains a pointer to a function table. Each entry in the function table points to a JNI function. Native methods always access data structures</p>
<p>The post <a href="https://studentprojects.in/software-development/jni/jni-tutorial/jni-part-3-mapping-types-passing-arguments/">JNI Part 3: Passing Arguments and Mapping Types</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<ol>
<li>The implemented JNI native methods have two standard parameters, in addition to the arguments declared in their Java-side declaration.</li>
<li>The first parameter, the JNIEnv interface pointer, points to a location that contains a pointer to a function table.</li>
<li>Each entry in the function table points to a JNI function.</li>
<li>Native methods always access data structures in the Java virtual machine through one of the JNI functions.</li>
<li>The second parameter differs depending on whether the native method is a static or an instance method.</li>
<li>The second argument to an instance native method is a reference to the object on which the method is invoked, similar to the ‘this’ pointer in C++.</li>
<li>The second argument to a static native method is a reference to the class in which the method is defined.</li>
<li>In the previous example, Java_HelloWorld_print() implements an instance native method. Thus the jobject parameter is a reference to the object itself.</li>
</ol>
<p><img decoding="async" loading="lazy" class="aligncenter wp-image-1666 size-full" title="JNI Passing arguments" src="https://studentprojects.in/wp-content/uploads/2011/08/JNI-Passing-arguments.png" alt="JNI Passing arguments" width="618" height="254" /></p>
<p><strong>Mapping Types</strong></p>
<ol>
<li>Argument types in the native method declaration have corresponding types in native programming languages.</li>
<li>The JNI defines a set of C and C++ types that correspond to types in the Java programming language.</li>
<li>There are two kinds of types in the Java programming language:
<ol>
<li>Primitive types such as int, float, double and char;</li>
<li>Reference types such as classes and arrays.</li>
</ol>
</li>
<li>The variables of primitive types contain a single value – a number, character or boolean value. A variable of primitive type has a specified size and format.</li>
<li>The variables of reference type contain a reference to (an address of) the value or set of values represented by the variable. Arrays, classes and interfaces are reference types.</li>
<li>The JNI treats primitive types and reference types differently.</li>
<li>The JNI passes objects to native methods as opaque references.</li>
<li>Opaque references are C pointer types that refer to internal data structures in the Java virtual machine.</li>
<li>The exact layout of the internal data structures, however, is hidden from the programmer.</li>
<li>All JNI references are of or inherit the type jobject.</li>
</ol>
<p><strong>Primitive types:</strong> <strong>There are eight primitive types in Java</strong></p>
<table class="tbl" border="0" width="450" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="200"><strong>Type</strong></td>
<td width="250"><strong>Description</strong></td>
</tr>
<tr>
<td>boolean</td>
<td>Similar to the C++ bool type but cannot be converted to int. An integer or pointer cannot be used in a boolean context (such as an if condition they way it can in C or C++.</td>
</tr>
<tr>
<td>char</td>
<td>Similar to the C char type but uses 16 bits.</td>
</tr>
<tr>
<td>byte</td>
<td>An 8-bit signed integer.</td>
</tr>
<tr>
<td>short</td>
<td>A 16-bit signed integer.</td>
</tr>
<tr>
<td>int</td>
<td>A 32-bit signed integer.</td>
</tr>
<tr>
<td>long</td>
<td>A 64-bit signed integer.</td>
</tr>
<tr>
<td>float</td>
<td>A 32-bit floating point number.</td>
</tr>
<tr>
<td>double</td>
<td>A 64-bit floating point number.</td>
</tr>
</tbody>
</table>
<p>The mapping of primitive types is straightforward.</p>
<p><strong>Example: </strong></p>
<ol>
<li>The type int in the Java programming language maps to the C/C++ type jint (defined in jni.h as a signed 32-bit integer),</li>
<li>The type float in the Java programming language maps to the C and C++ type jfloat (defined in jni.h as a 32-bit floating point number).</li>
</ol>
<table class="tbl" border="0" width="500" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="150"><strong>Java Type</strong></td>
<td width="150"><strong>Native Type</strong></td>
<td width="200"><strong>Size in bits</strong></td>
</tr>
<tr>
<td>boolean</td>
<td>jboolean</td>
<td>8, unsigned</td>
</tr>
<tr>
<td>byte</td>
<td>Jbyte</td>
<td style="text-align: left;">8</td>
</tr>
<tr>
<td>char</td>
<td>Jchar</td>
<td>16, unsigned</td>
</tr>
<tr>
<td>short</td>
<td>Jshort</td>
<td style="text-align: left;">16</td>
</tr>
<tr>
<td>int</td>
<td>Jint</td>
<td style="text-align: left;">32</td>
</tr>
<tr>
<td>long</td>
<td>Jlong</td>
<td style="text-align: left;">64</td>
</tr>
<tr>
<td>float</td>
<td>Jfloat</td>
<td style="text-align: left;">32</td>
</tr>
<tr>
<td>double</td>
<td>Jdouble</td>
<td style="text-align: left;">64</td>
</tr>
<tr>
<td>void</td>
<td>Void</td>
<td>n/a</td>
</tr>
</tbody>
</table>
<p><strong>Reference types:</strong></p>
<ol>
<li>Here Objects are passed by reference</li>
<li>All objects have type jobject as shown in below image</li>
</ol>
<p><img decoding="async" loading="lazy" class="aligncenter size-full wp-image-1671" title="JNI Object mapping" src="https://studentprojects.in/wp-content/uploads/2011/08/JNI-Objectmapping.png" alt="" width="612" height="332" /></p>
<p>The native code must manipulate the underlying objects via the appropriate JNI functions, which are available through the JNIEnv interface pointer.</p>
<p><strong>Example:<br />
</strong>The corresponding JNI type for java.lang.String is jstring. The exact value of a jstring reference is irrelevant to the native code. The native code calls JNI functions such as GetStringUTFChars() to access the contents of a string.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">
<p><!-- [if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML /> <o:AllowPNG /> </o:OfficeDocumentSettings> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves /> <w:TrackFormatting /> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF /> <w:LidThemeOther>EN-IN</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:SplitPgBreakAndParaMark /> <w:DontVertAlignCellWithSp /> <w:DontBreakConstrainedForcedTables /> <w:DontVertAlignInTxbx /> <w:Word11KerningPairs /> <w:CachedColBalance /> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math" /> <m:brkBin m:val="before" /> <m:brkBinSub m:val="&#45;-" /> <m:smallFrac m:val="off" /> <m:dispDef /> <m:lMargin m:val="0" /> <m:rMargin m:val="0" /> <m:defJc m:val="centerGroup" /> <m:wrapIndent m:val="1440" /> <m:intLim m:val="subSup" /> <m:naryLim m:val="undOvr" /> </m:mathPr></w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true" DefSemiHidden="true" DefQFormat="false" DefPriority="99" LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Normal" /> <w:LsdException Locked="false" Priority="9" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="heading 1" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9" /> <w:LsdException Locked="false" Priority="39" Name="toc 1" /> <w:LsdException Locked="false" Priority="39" Name="toc 2" /> <w:LsdException Locked="false" Priority="39" Name="toc 3" /> <w:LsdException Locked="false" Priority="39" Name="toc 4" /> <w:LsdException Locked="false" Priority="39" Name="toc 5" /> <w:LsdException Locked="false" Priority="39" Name="toc 6" /> <w:LsdException Locked="false" Priority="39" Name="toc 7" /> <w:LsdException Locked="false" Priority="39" Name="toc 8" /> <w:LsdException Locked="false" Priority="39" Name="toc 9" /> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption" /> <w:LsdException Locked="false" Priority="10" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Title" /> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font" /> <w:LsdException Locked="false" Priority="11" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtitle" /> <w:LsdException Locked="false" Priority="22" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Strong" /> <w:LsdException Locked="false" Priority="20" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Emphasis" /> <w:LsdException Locked="false" Priority="59" SemiHidden="false" UnhideWhenUsed="false" Name="Table Grid" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text" /> <w:LsdException Locked="false" Priority="1" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="No Spacing" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 1" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 1" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 1" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 1" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision" /> <w:LsdException Locked="false" Priority="34" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="List Paragraph" /> <w:LsdException Locked="false" Priority="29" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Quote" /> <w:LsdException Locked="false" Priority="30" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Quote" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 1" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 1" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 1" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 1" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 1" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 2" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 2" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 2" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 2" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 2" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 2" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 2" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 2" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 3" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 3" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 3" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 3" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 3" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 3" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 3" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 3" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 3" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 4" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 4" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 4" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 4" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 4" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 4" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 4" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 4" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 4" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 5" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 5" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 5" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 5" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 5" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 5" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 5" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 5" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 5" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 6" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 6" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 6" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 6" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 6" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 6" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 6" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 6" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 6" /> <w:LsdException Locked="false" Priority="19" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis" /> <w:LsdException Locked="false" Priority="21" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis" /> <w:LsdException Locked="false" Priority="31" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference" /> <w:LsdException Locked="false" Priority="32" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Reference" /> <w:LsdException Locked="false" Priority="33" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Book Title" /> <w:LsdException Locked="false" Priority="37" Name="Bibliography" /> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading" /> </w:LatentStyles> </xml><![endif]--><!-- [if gte mso 10]> <mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;} --> <!--[endif] --></p>
<p class="MsoNormal"><strong style="mso-bidi-font-weight: normal;"><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">Mapping Types</span></strong></p>
<p class="MsoNormal" style="margin-left: 36.0pt; text-indent: -18.0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: 14.0pt; line-height: 115%; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings;"><span style="mso-list: Ignore;">§</span></span><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">Argument types in the native method deMapping Types<br />
?    Argument types in the native method declaration have corresponding types in native programming languages.<br />
?    The JNI defines a set of C and C++ types that correspond to types in the Java programming language.<br />
?    There are two kinds of types in the Java programming language:<br />
?    primitive types such as int, float, double and char;<br />
?    reference types such as classes and arrays.<br />
?    The variables of primitive types contain a single value – a number, character or boolean value. A variable of primitive type has a specified size and format.<br />
?    The variables of reference type contain a reference to (an address of) the value or set of values represented by the variable. Arrays, classes and interfaces are reference types.<br />
There are eight primitive types in Java:<br />
claration have <strong>corresponding types</strong> in native programming languages. </span></p>
<p class="MsoNormal" style="margin-left: 36.0pt; text-indent: -18.0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: 14.0pt; line-height: 115%; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings;"><span style="mso-list: Ignore;">§</span></span><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">The JNI <strong>defines a set of C and C++ types</strong> that correspond to types in the Java programming language.</span></p>
<p class="MsoNormal" style="margin-left: 36.0pt; text-indent: -18.0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: 14.0pt; line-height: 115%; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings;"><span style="mso-list: Ignore;">§</span></span><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">There are two kinds of types in the Java programming language:</span></p>
<p class="MsoNormal" style="margin-left: 72.0pt; text-indent: -18.0pt; mso-list: l0 level2 lfo1; tab-stops: list 72.0pt;"><span style="font-size: 14.0pt; line-height: 115%; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings;"><span style="mso-list: Ignore;">§</span></span><strong><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">primitive types</span></strong><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">such as <strong>int, float</strong>, <strong>double</strong> and <strong>char</strong>;</span></p>
<p class="MsoNormal" style="margin-left: 72.0pt; text-indent: -18.0pt; mso-list: l0 level2 lfo1; tab-stops: list 72.0pt;"><span style="font-size: 14.0pt; line-height: 115%; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings;"><span style="mso-list: Ignore;">§</span></span><strong><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">reference types</span></strong><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">such as <strong>classes</strong> and <strong>arrays</strong>. </span></p>
<p class="MsoNormal" style="margin-left: 36.0pt; text-indent: -18.0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: 14.0pt; line-height: 115%; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings;"><span style="mso-list: Ignore;">§</span></span><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">The variables of primitive types <strong>contain a single value</strong> – a number, character or boolean value. A variable of primitive type has a <strong>specified size and format</strong>. </span></p>
<p class="MsoNormal" style="margin-left: 36.0pt; text-indent: -18.0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt;"><span style="font-size: 14.0pt; line-height: 115%; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings;"><span style="mso-list: Ignore;">§</span></span><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">The variables of reference type <strong>contain a reference to</strong> (an address of) the value or set of values represented by the variable. Arrays, classes and interfaces are reference types.</span></p>
<p class="MsoNormal"><strong style="mso-bidi-font-weight: normal;"><span lang="EN-US" style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US;">There are eight primitive types in Java:</span></strong></p>
</div><p>The post <a href="https://studentprojects.in/software-development/jni/jni-tutorial/jni-part-3-mapping-types-passing-arguments/">JNI Part 3: Passing Arguments and Mapping Types</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/jni/jni-tutorial/jni-part-3-mapping-types-passing-arguments/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to convert a jstring to a C-style string or vice versa?</title>
		<link>https://studentprojects.in/software-development/jni/jni-tutorial/convert-jstring-cstyle-string-vice-versa/</link>
					<comments>https://studentprojects.in/software-development/jni/jni-tutorial/convert-jstring-cstyle-string-vice-versa/#respond</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Sat, 20 Aug 2011 12:57:56 +0000</pubDate>
				<category><![CDATA[JNI Tutorial]]></category>
		<category><![CDATA[env]]></category>
		<category><![CDATA[GetStringUTFChars]]></category>
		<category><![CDATA[NewStringUTF]]></category>
		<category><![CDATA[string to jstring]]></category>
		<category><![CDATA[jstring to string]]></category>
		<category><![CDATA[jni]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1674</guid>

					<description><![CDATA[<p>The jstring type represents strings in the Java virtual machine, and is different from the regular C string type (a pointer to characters, char *).&#160; So we cannot use a jstring as a normal C string. We must use the appropriate JNI functions to convert jstring objects to C/C++ strings.&#160; The JNI supports conversion both</p>
<p>The post <a href="https://studentprojects.in/software-development/jni/jni-tutorial/convert-jstring-cstyle-string-vice-versa/">How to convert a jstring to a C-style string or vice versa?</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The jstring type represents strings in the Java virtual machine, and is different from the regular C string type (a pointer to characters, char *).&nbsp; So we cannot use a jstring as a normal C string. We must use the appropriate JNI functions to convert jstring objects to C/C++ strings.&nbsp; The JNI supports conversion both to and from Unicode and UTF-8 strings. Unicode strings represent characters as 16-bit values, whereas UTF-8 strings use an encoding scheme that is upward compatible with 7-bit ASCII strings. UTF-8 strings act like NULL-terminated C strings.</p>
<p>jstring, which requires a subroutine call to in order to convert a Java Unicode string (2 bytes) to a C-style char* string (1 byte UTF-8 format).</p>
<p>To convert a<strong> jstring to a C-style string</strong>, you might write code like the following:</p>
<pre lang="c" escaped="true" line="1">JNIEXPORT void JNICALLJava_MyJavaClass_printName(JNIEnv *env, jobject obj,
	jstring name)
{
	const char *str= (*env)-&gt;GetStringUTFChars(env,name,0);
	printf(“%s”, str);
	//need to release this string when done with it in order to
	//avoid memory leak
	(*env)-&gt;ReleaseStringUTFChars(env, name, str);
}</pre>
<p>To convert a<strong> </strong><strong>C-style string to </strong><strong>jstring </strong>, you can use the (*env)-&gt;NewStringUTF() function to create a new jstring from a C-style string. For example, a C function that needs to return a Java string could contain the following code:</p>
<pre lang="c" escaped="true" line="1">JNIEXPORT jstring JNICALLJava_MyJavaClass_getName(JNIEnv *env, jobject obj)
{
	return (*env)-&gt;NewStringUTF(env, “Electrofriends.com”);
}</pre><p>The post <a href="https://studentprojects.in/software-development/jni/jni-tutorial/convert-jstring-cstyle-string-vice-versa/">How to convert a jstring to a C-style string or vice versa?</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/jni/jni-tutorial/convert-jstring-cstyle-string-vice-versa/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
