• Post Reply Bookmark Topic Watch Topic
  • New Topic

java and c++  RSS feed

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello fellow javarians..

I have a chess program (engine + GUI) written in java.
I'm thinking of writing the engine using c++.
Is it possible for java code in the GUI, to pass a string into c++
project, and then retrieve a string, like a method call..

I know theres a native keyword(might be relevant), can this be done easily without lots of complications?

Thanks
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java Native Interface Specification

The most important benefit of the JNI is that it imposes no restrictions on the implementation of the underlying Java VM. Therefore, Java VM vendors can add support for the JNI without affecting other parts of the VM. Programmers can write one version of a native application or library and expect it to work with all Java VMs supporting the JNI.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

I got it working believe it or not...

Theres a fantastic explanation here...
JNI thing

Its a little complicated, lots of different files to make, but its not too difficult
 
Rancher
Posts: 4686
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so now that its working, how much faster is the C++ code?

This is one case that I might believe is really faster in C++, assuming you are doing deep searches
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeh, one small problem with that...
I haven't written the engine in c++, and I don't yet know the langauge.

I'm planning to copy the java engine exactly, but in c++ code.

I'm struggling to make the project portable.
I don't know if its possible, but seems to be problems cause of the paths to the jdk and gcc compiler.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're writing the software in C++ because you think it will run faster than Java, then you might get disappointed later with the speed of your C++ code, because Java really isn't that much slower than C++ nowadays.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thats true, also...
When you are doing a search in chess, even if you can get the effective branching factor at each node down to 6, the having a language that runs 6 times faster than java will produce a search of 1 ply deeper.

Its more a factor of program design than speed, however if you have a super computer like deep blue, then the speed alone will produce better results.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!