Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run java code that has been pasted into my program

I'm making a simulator for Time Complexity. The purpose is that Students can choose which algorithms they want to compare.

But I want to make it possible to compare algorithms they've written themselves. I know how to get it to work with a compiled .class file.

I was wondering whether it is possible for the students to just paste the code (with predefined public methods) and then just run it.

I suppose that I have to do something with javac.

Any ideas are welcome!

Thanks

like image 270
tgoossens Avatar asked Aug 16 '11 18:08

tgoossens


People also ask

How do I run a Java program after installation?

Once downloaded, install. in order to run Java from anywhere in your system, the files need to be added to your PATH variable in windows. To do this, go to 'Control Panel' -> 'System' -> the 'Advanced system settings' option on the left. Now under click 'environment variables' and then click edit on the PATH variable.

How do I run a Java project on another computer?

In Eclipse you can export you application via File -> Export -> Runnable JAR file Then you have to select the entry point (a class with a main-method) which should be called on running the jar-file. On the target computer you can normally run the jar file by double-clicking it (Java SE is required to be installed).


1 Answers

Use the JavaCompiler class. You will need to add tools.jar to your classpath if you don't already have it.

like image 57
Jeremy Avatar answered Oct 02 '22 02:10

Jeremy