C++ interaction with other language? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++ interaction with other language?

Can a c++ program, script run and change values of a program running or written in Java? Or what option is available?

9th Feb 2020, 3:32 PM
Benjamin Oterhals Stuen
Benjamin Oterhals Stuen - avatar
10 Answers
+ 2
java can use c++ library with JNI, so if you have a library written in C/C++ (not limited to them) you can use it in java code. or if both program are running at the same time, you can make them send and listen to each other. i remember i was using Socket to integrate running program in different devices as one system. socket is also avaiable in most of the language java ( https://docs.oracle.com/javase/8/docs/api/java/net/Socket.html ), python ( https://docs.python.org/3.5/library/socket.html ) in C++ i think its os dependent
9th Feb 2020, 4:59 PM
Taste
Taste - avatar
+ 1
you're welcome
9th Feb 2020, 5:11 PM
Taste
Taste - avatar
0
I believe for you to interact cross languages you'll need a middle man to decipher the languages between each other. I can't remember what technology I used at work for this, but there's something out there that's language agnostic(Like Javascript) that'll allow inputs from 2 server side languages to communicate to each other. I'd suggest looking into writing it in the same language if you don't want to work with a language agnostic technology, though. Alternatively, you could send your code up to the client(Javascript) and have Javascript be the middle man and communicate the information and send it back down if you want.
9th Feb 2020, 4:08 PM
Ronald Lemuel
Ronald Lemuel - avatar
0
nice. So javascript have the option to write c++ inside? if thats what you ment Ronald Lemuel
9th Feb 2020, 4:29 PM
Benjamin Oterhals Stuen
Benjamin Oterhals Stuen - avatar
0
So.. not exactly, basically you'll send the information up to Javascript, and Javascript can pass it back down to Java. Javascript can decipher whatever you send it, so it'll act as the middle man. You'll need to learn javascript in order to do this, though.
9th Feb 2020, 4:51 PM
Ronald Lemuel
Ronald Lemuel - avatar
0
ok, im currently learning c++ since i felt html was a bit more complicated to use
9th Feb 2020, 4:53 PM
Benjamin Oterhals Stuen
Benjamin Oterhals Stuen - avatar
0
but also, am i able to run a javascript from my part to change code or something, on a server sided program? like a game. to duplicate or some sort? Or what program can do that? its runned with .jar
9th Feb 2020, 4:54 PM
Benjamin Oterhals Stuen
Benjamin Oterhals Stuen - avatar
0
Nice. so with JNI and the .jar game and my script/menu can connect to eachother if im understanding this right, to edit or give commands from the c++ library into the game live? sorry if i ask alot, just want to understand it correctly
9th Feb 2020, 5:03 PM
Benjamin Oterhals Stuen
Benjamin Oterhals Stuen - avatar
0
yes, lets just make an example. your c++ had a job to render your game. and java for the logic, in this scenario when java want to render the game it'll call and execute function from your c++ library so the game will rendered.
9th Feb 2020, 5:08 PM
Taste
Taste - avatar
0
nice. ive just started with prob the hardest language. c++, and i fins it really interesting. tysm for help me Taste
9th Feb 2020, 5:10 PM
Benjamin Oterhals Stuen
Benjamin Oterhals Stuen - avatar