I was going through this article on java9 and came across this line where it states that Java is statement-oriented whereas REPLs are expression-oriented.
Can somebody explain the difference between these two?
I was going through this article on java9 and came across this line where it states that Java is statement-oriented whereas REPLs are expression-oriented.
Can somebody explain the difference between these two?
A very quick and coincidently visible difference is that following types of expressions can be made into a statement by terminating the expression with a semicolon (;
).
So when in your HelloWorld.java
class the following would not compile -
int z = 1 //(; missing)
Jshell on its prompt successfully stores the value as:
jshell> int z = 1
z ==> 1
Morevoer
Statements are roughly equivalent to sentences in natural languages. A statement forms a complete unit of execution.
whereas an Expression
is a construct made up of variables, operators, and method invocations, which are constructed according to the syntax of the language, that evaluates to a single value.