How to connect java and c++

Connection between java and c++ by Aryadrj

Step 1->

  •  You need Netbeans application with supported c++.
  • To download the netbeans with c++ click the link below


After Clicking the above link the following page will open
  • Click on Download All version


Step 2->
  • install both application i.e cygwin and neatbeans



Step 3->
  • Now Open the neatbeans 
  • Click the new project 
  • Choose java which is in right side.
  • Click on next and type HelloJava (for example) in project name.



Step 4->

  • Change the name Hellojava.java which is in left side
  • Change the name to Main.java then click on refactor.











  • Right click on Main.java  there you will see Generate JNI Library Project as shown in above image.
  • But you cannot click on that for now.. To enable that just go on step 5.




Step 5->

  • Delete all comments line
  • modify the following code in your terminal,see the image below
package hellojava;
public class Main
{
 public static void main(String[] args)
{       new Main().nativeGreeting();

}
private native void nativeGreeting();
}
  • save it.







Step 6->


  • Now right click on Main.java click on Generate the JNI Library project
  • If you are not getting Generate JNI Library Project Then go to tools->then Mixed Development->Generate JNI Library Project.



Step 7->

  • After clicking on Generate Jni then Type the project name as HelloNavtive 
  • Select the Tool collections as Cygwin
  • And then click on Finish.






Step 8->

  • See on left side->click on Hellonative(Jni project name).
  • Click on Source Files
  • Click on Main.h then you will see the code on right side.




Step 9->

  • Add some code there printf("hello world");as show in image below. 
  • Click on Hellonative which is in left side.
  • then Click build if build successful then go to step 10. 



Step 10->
  • Go to Main.java Which is in HelloJava on the top
  • Type System.LoadLibrary("LibHelloNative"); shown in image
  • Then right click on HelloJava the choose option run.







Step 11->

  • After you click run,Hello world output will come at button then 
  • Congrats the java and c++ is connected



Notes
if your output is not comming then you have to do some path setting

Go to Mycomputer->Then System properties->Then advance System setting->Then Enviroment variables->Then choose path in System variable->Then type C:\cygwin64\bin;  Or C:\cygwin\bin;  Whatever you have saved cigwin name in c drive just check and add at the end of text see in image below


Thank you.. if any doubt then Email me->
Aryadrj@gmail.com

Comments

Post a Comment

Popular posts from this blog

How to set image in carousel using flask?

Invalid syntax , perhaps you forgot a comma? Error in Python

Cyber Security Capsule