So to explain my question, I would like to be able to write code inside a JTextField and with a press of a button my program would take that code, and execute it.
Is that even possible with normal java?
You could save the contents of the text field to a file with the .java extension, then compile it and run the corresponding binary with Runtime.getRuntime().exec("javac " + [insert the name of your java file here]); and Runtime.getRuntime().exec("java " + [insert class name here]);. Though of course this wouldn't validate that the contents of the text field are valid java, nor would it work for any sufficiently complex code. For that, you'd basically be writing your own IDE, which is a task too complex to be discussed in a Stack Overflow answer.
Yes. Short outline:
javax.tools.ToolProvider.getSystemJavaCompiler();)final URLClassLoader classLoader = new URLClassLoader(new URL[] { new File("./").toURI().toURL() });final Class<?> loadedClass = classLoader.loadClass(pFullClassName);All in all it is hell to implement all that, took me 3 full days to have it working all in RAM without temporary files. Usually it's easier just to use some runtime container for JavaScript or something alike.
AND there may be probles, like when getting the compiler: it might not be present in your JVM. You'd have to run the code in a JDK, or add the Java Compiler jars to your classpath.
JTextAreafor the code.