title: jstring return in JNI program
body: <p>This is JNI code.</p>
  <p><em>Java code:</em></p>
  <pre class="lang-java prettyprint-override"><code>public class Sample1 {
   
      public native String stringMethod(String text);
      
      public static void main(String[] args)
      {
         System.loadLibrary(&quot;Sample1&quot;);
         Sample1 sample = new Sample1();
      
         String  text   = sample.stringMethod(&quot;world&quot;);
      
         System.out.println(&quot;stringMethod: &quot; + text);    
     }
  }
  </code></pre>
  <p><em>Cpp Method for stringMethod function:</em></p>
  <pre class="lang-cpp prettyprint-override"><code>JNIEXPORT jstring JNICALL Java_Sample1_stringMethod
     (JNIEnv *env, jobject obj, jstring string) {
     
   const char *name = env-&gt;GetStringUTFChars(string, NULL);//Java String to C Style string
   char msg[60] = &quot;Hello &quot;;
   jstring result;
  
   strcat(msg, name);
   env-&gt;ReleaseStringUTFChars(string, name);
   puts(msg);
   result = env-&gt;NewStringUTF(msg); // C style string to Java String
   return result;    
   }
  </code></pre>
  <p>When running my java code. I got the result below.</p>
  <pre><code>stringMethod: world
  </code></pre>
  <p>But I appended the string &quot;world&quot; with &quot;Hello &quot;. I'm also returning here the appended string. But why I'm getting only &quot;world&quot; not &quot;Hello World&quot;. Really I confused with this code. What should I do to get the result with appended string?</p>