I am working on a project that involves having a Java code editor and a Python code editor but I have no way of compiling that code. I've used Ace within my html and I have no idea how to compile the Java code or Python code using JavaScript. I currently have a way of retrieving all of the Java/Python code to a string. From there I need a way of compiling that code so that I can run it on my website and test it. There will be no GUIs involved, all of the Java/Python code will just have console output. However, I need a way I can run the Java/Python code on my website in live speed. Everything must be done on the website, the client shouldn't have to download anything extra. I am basically trying to replicate the website 'codingbat.com'. Thanks for the help in advance.
Python would usually get JITted when you invoke a good Python interpreter (ha, the name does not apply). Java has some great compilers (standard javac or the Eclipse JDT) so I would not even think of compiling with some other language.
Where does the need come from to cross-compile in JavaScript? It sounds like you are searching for a Java compiler implemented in JavaScript, and likewise for Python.
If everything has to be built and deployed to some website, why don't you create a script (shell, JavaScript, or a Jenkins Pipeline) that compiles the java part using javac, precompiles the python part as required and deploys the output directly to your website?
Related
I am creating a test case website to allow students to solve some programming questions and test their code. I am using express and Node Js.
I am planning to add multiple languages such as Javascript, Python, and Java.
For javascript, I was able to use vm2 sandbox to safely run the user's arbitrary code. Go here to see how I did it.
However, I am still not sure about how to implement it for Java and Python.
For Python, there is the build-in "child_process" that allows running a python script which is basically another python file and allows us to get the output from it. What I want is to get the user's code from a text area and run it inside the app.js file.
Is there any library or sandbox that allows me to do that?
I am a little curious about how javascript frameworks work. Web development isn't really my area of expertise (I'm more of a c/c++ guy), but do javascript frameworks get translated into vanilla javascript?
Upon inspection of website source, it seems like it is mostly just standard javascript. Do these javascript engines just translate code into javascript on the server side?
Yes, most of JavaScript Frameworks translates the code you write to vanilla JavaScript, however, this does not happen on the Server Side, that would be really slow (Server side code is used to check databases, serve files, authenticate, etc.). This process of translation is done in compilation time (Although it is translation). (Just like when you compile c++ code into binary).
When it's source code to source code like JavaScript and React (JSX) to Vanilla JavaScript (JS), it's translation. When it's source code to binary like C++ source code to an executable (.exe) is compilation.
After you're done writting your JavaScript code with frameworks, you most translate it to Vanilla JavaScript (if you also used other uncommon languages to write styles, you must translate them too, like SASS instead of CSS). It is also common to minify it, so it can load faster.
All this is mainly done by tools like webpack.
When your site is up and running, we can say that is run time.
Looking at the fact that they were written in js they would be resolved to js before running and as Robin said they are executed on client side except Node which is a runtime environment and not a framework
I have a website written in html and I have a button that when clicked should run a python script. The button is programmed in javascript, and I have seen on this site how to connect javascript and python together, but the problem is that I'm running the website using xampp and localhost, so I don't know the configurations to run the python code. I have tried to use up mod_wsgi, but the instructions are very confusing and I really have no idea what I'm doing.
I don't want to use JQuery or Ajax, I'd rather use just regular javascript to run the python code. How would I accomplish this? Basically I just want the button to run a python script I have, which is in the same directory as the website is. I don't want to run the python code from localhost directly, rather I want to reference and run it from the javascript code for the button.
Edit: it has been pointed out to me that JavaScript and python are connected through a client server relationship. Therefore my question is how to run the python code through a webserver from xampp.
Thanks in advance
I want build a simple webpage so I can write a C++ code in html page and run the code, then the result showing in the same page.
Is it possible to do this?
If so is there any idea how can I get started?
It is not possible to execute C++ code directly in a browser. It is possible to compile and generate the HTML for a website with C++, though. Visual Studio will help you setup a website built on C++.
I know there are lots of libraries that read byte codes that are written in Java. Does someone know of a byte code library that is implemented in Javascript?
Since javascript is typically run inside a browser, it generally cannot read the actual bytes out of files, which makes it less-than-ideal for reading java bytes. If you somehow got the byte codes encoded in a form that the javascript could read, what would you expect the library to do with it? Can you provide more details about what you're trying to do?
If you're looking to be able to write code in Java, and have it run inside a browser, take a look at GWT. It uses Java to recompile your byte-code into optimized javascript.
Edit
Based on your added comment, that you are hoping to "find out the classes and methods used in a jar file on my local disk":
Since javascript is unable to access files on a local disk (at least, without using ActiveX), the technology simply won't allow for this sort of thing. Is there a reason you wanted to use javascript for this, rather than java?
And please accept my apologies if it sounded like I was questioning your motives. I really just wanted to get enough information to be able to adequately answer your question.
Update:
It looks like the Japanese project I tried to link to below is long gone.
In any case, time has passed and now there are a couple of hits for "jvm in javascript" on Google. Namely:
Doppio
BicaVM
Look what I found:
http://ejohn.org/blog/running-java-in-javascript/
Does this help?
Edit: unfortunately it looks like the original project's site is dead.
You could try through the Web Archive, here (in Japanese, tried to Google translate it, but I guess it was too much indirection :))
For goodness sake, if you follow that link, run your download through an anti-virus.
I don't know if it's trustworhty.
There are compilers which can compile Java to JavaScript. As a last resort, you can use one of those compilers to take a JVML bytecode disassembler written in Java and compile it to JavaScript. One example of such a compiler is GWT.
Similarly, there are compilers which can compile JVML bytecode to JavaScript. Again, you can take one of the above JVML bytecode disassemblers written in Java, use any Java-to-JVML compiler (javac, ecj, gcj, …) to compile it to JVML (i.e. .class files), then compile those .class files to JavaScript.