Questions tagged [jshell]

JShell is a Read–Eval–Print Loop (REPL) tool to evaluate declarations, statements, and expressions of the Java programming language, together with an API so that other applications can leverage this functionality.

The JShell provides a way to interactively evaluate declarations, statements, and expressions of the Java programming language within the JShell state.

The JShell state includes an evolving code and execution state. To facilitate rapid investigation and coding, statements and expressions need not occur within a method, expressions need not have side-effects, variables need not occur within a class, and methods need not occur within a class or interface.

Furthermore, JShell can be used to create and run scripts.

Goals

  • The JShell API and tool will provide a way to interactively evaluate declarations, statements, and expressions of the Java programming language within the JShell state. The JShell state includes an evolving code and execution state. To facilitate rapid investigation and coding, statements and expressions need not occur within a method, and variables and method need not occur within a class.

  • The JShell tool will be a command-line tool with features to ease interaction including: a history with editing, tab-completion, automatic addition of needed terminal semicolons, and configurable predefined imports and definitions.

Non-Goals

  • A new interactive language is not the goal: All accepted input must match grammar productions in the Java Language Specification (JLS). Further, within an appropriate surrounding context, all accepted input must be valid Java code (JShell will automatically provide that surrounding context -- the "wrapping"). That is, if X is an input that JShell accepts (as opposed to rejects with error) then there is an A and B such that AXB is a valid program in the Java programming language.

  • Out of scope are graphical interfaces and debugger support. The JShell API is intended to allow JShell functionality in IDEs and other tools, but the JShell tool is not intended to be an IDE.

201 questions
-1
votes
1 answer

It is possible to paste a whole Class on JShell?

I would like to know if using the new command jshell, it is possible to test a whole Java class. Many thanks in advance. Juan antonio
jabrena
  • 1,166
  • 3
  • 11
  • 25
-2
votes
1 answer

How to get the value passed to a variable?

I am trying to evaluate a code snippet that has variables initialised to a value. Is there a way to get the field values using java? For the below code: public void testArea(){ int length = 5; int breadth = 6; ... } Suppose this is the…
Rakshita
  • 1
  • 2
-2
votes
2 answers

How do you load an external file in JShell?

JShell is the interactive REPL command line for Java. If I have a Java class with some methods that I would like to play around with interactively in a .java file, how do I load that file in? Let's say I have the file HelloWorld.java: class…
ziggurism
  • 2,264
  • 2
  • 16
  • 23
-2
votes
1 answer

How to reset to default editor in jshell, in current sessoin?

In current session, I had set an external editor which I want to revert to default one. So, how to reset to default editor in jshell, in current sessoin? EDIT: I searched on net and found this link…
lupchiazoem
  • 8,026
  • 6
  • 36
  • 42
-2
votes
1 answer

Jshell - Why System.out.printf is populating this answer

Can any one help me to figure out the mistake i am doing. The expected is to print 4%2 as 0. I had tried both ways.
Drup
  • 79
  • 1
  • 5
-3
votes
4 answers

I'm trying to print out prime number but not sure what's wrong with my code

My code void printPrimes (int max) { boolean prime; for (int n = 2; n < max; n++){ prime = true; double maxF; maxF = Math.sqrt(n); for (int f = 2; f < maxF; f++) { if (n % f == 0) { …
Faraj
  • 1
1 2 3
13
14