JShell
{{Multiple issues|
{{Lead too short|date=June 2024}}
{{Context|date=June 2024}}
}}
JShell is a Java read-eval-print loop which was first introduced in the JDK 9.
{{cite web
| archive-url=https://web.archive.org/web/20170922110128/https://www.oracle.com/corporate/pressrelease/java-se-9-and-ee-8-092117.html
| archive-date=2017-09-22
| url-status=dead
| url=https://www.oracle.com/corporate/pressrelease/java-se-9-and-ee-8-092117.html
| publisher=Oracle Corporation
| title=Oracle Announces Java SE 9 and Java EE 8
| date=2017-09-21
| accessdate=2017-09-25
}} It is tracked by JEP 222 jshell: The Java Shell (Read-Eval-Print Loop).
{{cite web
| url=http://openjdk.java.net/jeps/222
| publisher=Oracle Corporation
| title=JEP 222: jshell: The Java Shell (Read-Eval-Print Loop)
| quote=Provide an interactive tool to evaluate declarations, statements, and expressions of the Java programming language, together with an API so that other applications can leverage this functionality
| date=2016-10-10
| accessdate=2016-11-01
}} One reason why JShell was proposed for Java 9 is the lack of a standard interactive environment for the language; the de facto library to use a Java REPL was often BeanShell, which has been dormant since 2003, and arbitrarily diverged from the Java language.
{{cite web
| url=http://openjdk.java.net/jeps/222
| publisher=Oracle Corporation
| title=JEP 222: jshell: The Java Shell (Read-Eval-Print Loop)
| quote=Another alternative is to maintain the status quo: Use another language or use a third-party REPL such as BeanShell, though that particular REPL has been dormant for many years, is based on JDK 1.3, and makes arbitrary changes to the language.
| date=2016-10-10
| accessdate=2016-11-01
{{cite web
| archive-url=https://web.archive.org/web/20150905160031/https://jaxenter.com/jshell-the-java-9-repl-what-does-it-do-120299.html
| archive-date=2015-09-05
| url-status=dead
| url=https://jaxenter.com/jshell-the-java-9-repl-what-does-it-do-120299.html
| publisher=jaxenter.com
| title=JShell, the Java 9 REPL – What does it do?
| quote=BeanShell (just like Groovy, too by the way) made an attempt of standardisation by the Java Community Process in JSR 274 – a JSR that did not produce any notable output, in spite of the fact that (or perhaps because?) two major companies, Sun and Google, had joined the expert group. Under the JCP.next initiative this JSR was declared “Dormant”.
| date=2015-09-03
| accessdate=2016-11-01
}}
Example
jshell> int a[] = { 0, 1, 3, 5, 8 }
a ==> int[5] { 0, 1, 3, 5, 8 }
jshell> int fact(int n) {
...> return n < 2 ? 1 : n * fact(n - 1);
...> }
| created method fact(int)
jshell> for (int i = 0; i < a.length; ++i)
...> a[i] = fact(a[i]);
jshell> a
a ==> int[5] { 1, 1, 6, 120, 40320 }
See also
References
{{DEFAULTSORT:Shell}}
Category:Cross-platform software
Category:Interpreters (computing)
{{prog-lang-stub}}