You can't do either. You might be able to find a compiler that compiles C++ into Java byte-code, or vise versa, but odds are it won't work depending on what libraries the program relies on.
Why would you want to do either, you can do anything you want in either languages, many libraries exist for both languages why not just use those.
/* Java */
package org.test.Test;
publicclass Test
{
public Test() { }
private native void print();
privatevoid print2() { System.out.println("Test From Java"); }
publicstaticvoid main(String[] args)
{
System.loadLibrary("Test");
Test test = new Test();
test.print();
}
}
/* C++ */
/* Make me into *.dll or *.so */
/* With GCC, use flag --Wl,kill-at */
/* MSVC Works without confusing obscure compiler flags */
#include <jni.h>
#include <iostream>
extern"C"
{
JNIEXPORT void JNICALL Java_org_test_Test_print(JNIEnv* env, jobject thisPointer)
{
std::cout << "Test" << std::endl; // <-- Calling C++ from Java
env->CallVoidMethod(thisPointer, env->GetMethodID(env->FindClass("org/test/Test"), "print2", "()V"); // <-- Calling Java from C++
}
}
Are there any simple, tutorial-like, examples ?
I haven't seen any decent tutorials that cover everything that you need to know before working with it. Sun/Oracle has one out, but it seems outdated and it doesn't cover any of the pitfalls that you can encounter like caching environment contexts and threading in enough detail.