Internal Java Language? (Language run within java) [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have started a large project, and require some sort of scripting language that can be stored as plain text, and ran within the JVM very fast during execution. I require a language that is simple, customizable, has various Java API's/Libraries to interpret, and can be stored within a large XML file either in an attribute or the inside of a XML node.
This is required so my program can dynamically write code that it will use later, in a neural network.

LUA is the perfect fit for an interpreted language that you want embed in Java:
http://lua-users.org/wiki/LuaImplementations
A more mainstream possibility is to call Jython from Java:
http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html
Another possibility is to use Java only and invoke the compiler at run time:
http://stackoverflow.com/questions/2946338/how-do-i-programmatically-compile-and-instantiate-a-java-class
Using an interpreted language will start the exection of the script faster but the execution itself will be slower. Using the Java compiler will cost more upfront but the execution will be faster and you will be sticking to a single language.

Related

Can I code a Java program that will call a program in another language (Rust) to do some calculations? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'd like to make a simulation, but I'd like to write the code to display the state of the simulation and the user interaction (frontend?) in Java (Kotlin actually, but I don't think it is relevant here) for the JVM, and I'd like to write the actual code of the simulation (backend?) in Rust. Mostly because I think it would be neat and that I would learn something.
Can I achieve this, and if yes, how? It might be relevant that the data that needs to be exchanged between the two programs is just a fixed-size array of floats.
Thank you for your help.
A Rust program compiles to native code (executable or shared library). To call native code from Java you have to use JNI: https://www.baeldung.com/jni.
You may find the jni crate useful for the Rust side of the project: https://docs.rs/jni/0.16.0/jni/

What is the java equivalent for Perl's require command? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am completely new to cgi concepts.
I'm given a task to convert a Perl cgi script to Java program.
I understood that the require 'file.ext' command in Perl includes the file available for code in the Perl script.
Because of the very limited resources and improper documentation I couldn't find any proper info.
Is there any Java equivalent to do the same action that require in Perl does?
The paradigms do not map at all. In Perl, require simply reads a file and runs the code in it, and everything else happens as side effects of that. In Java, your code must be compiled, and classes are included automatically when you compile your program. See Extend a java class from one file in another java file for more answers on this topic.

How to run java code in HTML [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a piece of java code I would like to run in my web browser and publish online. How can I do this without using applets? I have tried java vertx but I am not sure how to use it and there are no good tutorials online.
The short answer is you can't. Browsers don't "speak" Java natively, which is why applets required a plugin. As you probably know, Google is in the process of removing support for the plugin technology used by the Java plugin (NPAPI) and so soon Java won't work in Chrome at all (it already doesn't under Linux).
Your only real options are:
Provide a means of running it server-side, like http://ideone.com and various other "online" compilers do.
Translate it from Java to JavaScript (either manually or using a tool), which the browser can then run. But note that Java and JavaScript are not only markedly different languages despite a superficial similarity in syntax, but the standard environment for each is also quite different from the other.
How you do either of those is much too broad a question for SO.

interoperability java and c++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i want to write a program in two different languages java and c++ that needs a dynamic and interactive communication between its c++ component and java component.i know there is jni and jna for invoking native methods in java but i do not think this method is appropriate for my purpose.
for example : say a program that its User Interface is written in c++ and other in java, i do not think that communicating these two component can be done through jni and jna. for example Open Office is written in java and c++.
i searched the internet and find some method for Inter-process communication
like shared memory , pipe, signals, Message passing , ... but i don not know that Inter-process communication is what i need. it seems ipc is for communicating software in two different process but my program all is one process(am i right?!)
so my question is : how the programs that its component is written in different language communicate together? and how i can achieve this?
JNI has been exactly created for the purpose that you are describing; why exactly is it not "what you need"?
One other option: message brokers with implementations for different languages, like http://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol
But as you are stressing the latency, this might not be for your.

Executing Java programs through Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How do I do this?
You can execute anything you want from Python with the os.system() function.
os.system(command)
Execute the command
(a string) in a subshell. This is
implemented by calling the Standard C
function system, and has the same
limitations. Changes to os.environ,
sys.stdin, etc. are not reflected in
the environment of the executed
command.
For more power and flexibility you will want to look at the subprocess module:
The subprocess module allows you to
spawn new processes, connect to their
input/output/error pipes, and obtain
their return codes.
Of course, Jython allows you to use Java classes from within Python. It's an alternate way of looking at it that would allow much tighter integration of the Java code.

Categories

Resources