Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8039551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:36:24+00:00 2026-06-05T03:36:24+00:00

I have Class in java called XMLDOMDocument this class have some methods CreateXML ,

  • 0

I have Class in java called XMLDOMDocument this class have some methods CreateXML, AddNode, RemoveNode etc. I call this methods from C code with the help of Java Native Interface, but for doing that I pass to the C code object of my JAVA class then by calling env->GetObjectClass(myclass) I get my class from that object and call methods of the JAVA class.

I want to know can I do same thing (call JAVA methods) without passing my class to the C code. Can I create JAVA class right in C code and then call it’s methods.

Edited

And if I have JavaVM in my C code can I create a new instance of JAVA class in C code with the help of that Java VM.

Edited

I think I found something useful Creating the Java Virtual Machine, but I want to understand what value must be stetted #define USER_CLASSPATH ? If that must be package name com.fido.android.framework.service

public class Prog {
     public static void main(String[] args) {
          System.out.println("Hello World " + args[0]);
     }
 }

#include <jni.h>

 #define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */
 #define USER_CLASSPATH "." /* where Prog.class is */

 main() {
     JNIEnv *env;
     JavaVM *jvm;
     jint res;
     jclass cls;
     jmethodID mid;
     jstring jstr;
     jclass stringClass;
     jobjectArray args;

 #ifdef JNI_VERSION_1_2
     JavaVMInitArgs vm_args;
     JavaVMOption options[1];
     options[0].optionString =
         "-Djava.class.path=" USER_CLASSPATH;
     vm_args.version = 0x00010002;
     vm_args.options = options;
     vm_args.nOptions = 1;
     vm_args.ignoreUnrecognized = JNI_TRUE;
     /* Create the Java VM */
     res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
 #else
     JDK1_1InitArgs vm_args;
     char classpath[1024];
     vm_args.version = 0x00010001;
     JNI_GetDefaultJavaVMInitArgs(&vm_args);
     /* Append USER_CLASSPATH to the default system class path */
     sprintf(classpath, "%s%c%s",
             vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
     vm_args.classpath = classpath;
     /* Create the Java VM */
     res = JNI_CreateJavaVM(&jvm, &env, &vm_args);
 #endif /* JNI_VERSION_1_2 */

     if (res < 0) {
         fprintf(stderr, "Can't create Java VM\n");
         exit(1);
     }
     cls = (*env)->FindClass(env, "Prog");
     if (cls == NULL) {
         goto destroy;
     }

     mid = (*env)->GetStaticMethodID(env, cls, "main",
                                     "([Ljava/lang/String;)V");
     if (mid == NULL) {
         goto destroy;
     }
     jstr = (*env)->NewStringUTF(env, " from C!");
     if (jstr == NULL) {
         goto destroy;
     }
     stringClass = (*env)->FindClass(env, "java/lang/String");
     args = (*env)->NewObjectArray(env, 1, stringClass, jstr);
     if (args == NULL) {
         goto destroy;
     }
     (*env)->CallStaticVoidMethod(env, cls, mid, args);

 destroy:
     if ((*env)->ExceptionOccurred(env)) {
         (*env)->ExceptionDescribe(env);
     }
     (*jvm)->DestroyJavaVM(jvm);
 }

I also want to know the difference between passing class object from java to C and creating java class right in C

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:36:26+00:00Added an answer on June 5, 2026 at 3:36 am

    The CLASSPATH should be defined the same way you would pass it when launching the Java Virtual Machine. So if you want to create a class that is inside the com.fido.android.framework.service package, you would put the generated C executable in some directory, and the compiled Java class inside a com/fido/android/framework/service sub-directory. That way you do not need to change the CLASSPATH define

    The package name should be passed in the FindClass call:

    cls = (*env)->FindClass(env, "com/fido/android/framework/service/Prog");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called XMLtoXML.java and this is one of it's methods... import
I have this class called PollFrame that extends JFrame in a file called PollFrame.java
I have a Java class which can be called from shell. (via java [command][options])
I have an Android activity called main.java and BPMClass.java class. I need to call
For instance, I have a class called My_Class_X123.java like this : public class My_Class_X123
Hi I have a class called ColorChooser (in the net.java.dev.colorchooser.ColorChooser package) This is a
Java Code In Java code I have class called IdentificationResult which has 3 members:
I have a class which handle a location service called MyLocationManager.java this is the
In my MIDLet I have an instance of the java class ImageFetcher called anImg.
I have a class User with one field called birthDate which is a java.sql.Date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.