Java bytecode compiler in JavaScript - java

I'm looking for a standard Java to Java bytecode compiler implemented in JavaScript.
Has anyone heard of anything that can accomplish this?

There are several here: https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS
Such as j2js, bicavm, doppio...(see the java section)

if your goal is to have users write Java in a browser and see it run, it makes.MUCH more sense to do the compiling and executing server side. A servlet could read the code, compile it and run it, then push the output back to the browser.
unless your thesis is "Anything that can be written in JavaScript will eventually be written in JavaScript."

Related

How to package a python script with my java program?

So, I'm writing a program(mostly for practice, kind of for future convenience) that will show a java front-end when run, and depending on the input, will use a python script to crawl and interpret a webpage, then send the interpreted data back to java to format for the front end. I'm sure I can get this running on my own computer, but when I want to distribute my program for my friends to use, how can I ensure my java program, mainProgram.jar can find my python code, script_x.py. Is there a way I can assure my python script will be supported. I've read that there are ways to include the necessary runtimes and such with your program when you build it, but would it still interact the same way with my java program if it was bundled with it's dependencies? I can provide some sample code soon, but it's still a work in progress, as I don't have the python script finished yet.
here is a link https://bytes.com/topic/python/insights/949995-three-ways-run-python-programs-java
use Jython (compiles to java byte code) https://en.wikipedia.org/wiki/Jython
distributing Jython applications: https://wiki.python.org/jython/JythonFaq/DistributingJythonScripts

How to make a PHP library work in java environment?

i have a php library which is in php. can i have this lib to work in java environment like calling the functionalists of the lib to work exactly like a java lib?
Regards
Tony
Short answer: No
Long answer: No, you can't... They are two completely different languages.
Java runs on the JRE as a platform. The PHP interpreter run natively on the OS on which it runs.
The best you could do is run PHP as a system process passing the PHP file you want to run as an argument, and capture that process' output. (ie: run "/path/to/php myfile.php", and read the output).
However, I should warn you that this is a horribe idea, and you should really re-think what you're doing. You java code will loose it's portability completely, as well as become awfully designed.

Run Java in your web browser

Is there a way to run a Java command line in a web page along the lines of this Ruby web page:
http://tryruby.org/levels/1/challenges/0
The aim is to be able to give complete newbies a very simple introduction to the language without having to worry about IDEs, compilation, etc.
Well, since Java is a compiled language and has no REPL, there is no such "command line". But I can think of theoretically possible ways to implement the idea.
An Applet might be not really a solution. I don't know how far you can get with limited permissions. Security concerns might allow you to only operate in a sandbox and / or not to compile / execute code.
A Java WebStart application might have such permissions. It would be a similar task to provide a slim IDE. Or making Bluej run from WebStart.
Provide a web application that simply files a request to a server which compiles and executes the code and returns the result. I assume (I'm not sure) many online REPL work like this. (By skimming the JavaScript of try python I think it files AJAX requests) But then there's still a security concern, like what if a programm begins to randomly remove files? Google Appengine has advanced security mechanisms to prevent missuse. To implement them for "try java" it would require advanced effort.
Next idea is to limit everything down to a subset of the Java language. For providing a small introduction, a little tutorial with predefined answers and maybe a bit basic math you could write some JavaScript on the client side to decide wether the learner's answers are correct or not.
Don't forget that web-based IDEs are currently developed, for instance Eclipse Orion. Maybe you could watch these projects evolve and use them for such purpose. Currently I've only seen JavaScript code edited in there, and executing JS is one of the webbrowsers natural capabilities. I don't know which programming languages they are going to support or if code execution will be supported.
But usually java needs to be compiled to be useful to a JVM. So I am not sure you can do anything like that that would be useful for java. The key difference is in the interpreted (Ruby) vs compiled (java) implementation.
See What's the difference between compiled and interpreted language?

compiling java from within python

I'm making an application where people can upload a java code and do stuff with it.
The application i'm making is in Python. I was wondering whether it was possible to call the 'javac' command from within python, in order to compile the uploaded java file
I'm also using JPype
http://docs.python.org/library/subprocess.html
But are you sure that allowing people to submit arbitrary code is a good idea? There are security aspects of that to consider...
Entirely possible: just use the system command and invoke the java compiler. You'll probably need to set class paths and things of that nature, but it should work fine.
EDIT: see http://docs.python.org/library/os.html#os.system and http://docs.python.org/library/subprocess.html#module-subprocess for detail on invoking sub processes. You'll probably want to capture the output to return to the user in the event of a compile error.

How to run Java code using Java code?

Basically, I want to do two things:
I want to know if there is any way that I can run Java code using Java code.
If it is possible, how would I show the output on my screen? (be it regular output or error or exception)
I know this is possible because one of my seniors had done it, but I don't know how he did it. Maybe he used one of Java's built-in classes.
Note: user will write the code in some text file and then I will store that file content in some variable and then maybe run that code.
Yes, it is possible.
Step 1: Compile the Code
Use ProcessBuilder or Runtime to construct a Process in which the Java compiler compiles their code. (Note that this requires that a Java compiler be available on the system at runtime).
Step 2: Invoke their Code
There are two ways to invoke their code. You can again use a ProcessBuilder or Runtime object to construct a process in which you execute their Java code. You can use the Process's getInputStream and getOutputStream functions to read from and write to the other process. An alternative is that you can use Class and the various reflection APIs to load their code and execute it directly within Java.
You would have to some how invoke a compiler (such as Suns javac), parse its output in case of errors and load the resulting classes dynamically.
There is no API-classes in the Java runtime library that will parse, compile and run Java source code.
If you want an interpreter (so, no compiling required) for Java, take a look at BeanShell.
I like this one very much!
You can use a scripting language running on top of the JVM. Groovy is a very good idea and it has very similar syntax compared to Java.

Categories

Resources