I want to get a String
from the user like "System.out.println(\"Hello World!\");"
or "int x = 2;"
and then execute that input at runtime in java, I know that in python there is a built in function called exec()
that do what exactly what I want here.
Asked
Active
Viewed 46 times
0

thakee nathees
- 877
- 1
- 9
- 16
-
1Although Python's `eval()` and `exec()` are not identical, they are close enough for this purpose that the answer is the same. Especially since it's "no". – John Bollinger Feb 21 '19 at 12:53
-
2Java is a compiled language, Python is an interpreted one. For Java is not a simple task to do compilation on the fly. – Ervin Szilagyi Feb 21 '19 at 12:54