Python has a nice feature where I just type "python" in sh and I get an interactive way of testing Python code.
How do I do that with Java?
I'm on Mac 10.9 if that makes any difference.
Python has a nice feature where I just type "python" in sh and I get an interactive way of testing Python code.
How do I do that with Java?
I'm on Mac 10.9 if that makes any difference.
There is no such thing built into Java. However Beanshell might be what you are looking for:
You can use BeanShell interactively for Java experimentation and debugging as well as to extend your applications in new ways.
http://www.beanshell.org/intro.html
It however doesn't look like there's much development going on these days and other approaches (such as the mentioned Jython one) might be more practical.
What you are looking for is called a "REPL" which is short for "Read–eval–print loop".
Since Java 9 there is a REPL bundled with Java, it is called jshell
.
$ jshell
| Welcome to JShell -- Version 11.0.2
| For an introduction type: /help intro
jshell> int x = 4
x ==> 4
jshell> int y = 9
y ==> 9
jshell> x + y
$3 ==> 13
jshell> /exit
| Goodbye
$
Python is scripting language means that it is not compiled language but it is interpreted language.
Wikipedia definition for Interpreted language
While Java is compiled language and you will never find such a feature link in python interactive mode, becuase you must write the whole application structure main class to make your app run. So instead you can use an IDE like eclipse , or netbeans.
And also you can refere to stackoverflow link Compiled vs. Interpreted Languages