Presentation is loading. Please wait.

Presentation is loading. Please wait.

JShell: An Interactive Shell for the Java Platform

Similar presentations


Presentation on theme: "JShell: An Interactive Shell for the Java Platform"— Presentation transcript:

1

2 JShell: An Interactive Shell for the Java Platform
This is a Title Slide with Picture slide ideal for including a picture with a brief title, subtitle and presenter information. To customize this slide with your own picture: Right-click the slide area and choose Format Background from the pop-up menu. From the Fill menu, click Picture and texture fill. Under Insert from: click File. Locate your new picture and click Insert. To copy the Customized Background from Another Presentation on PC Click New Slide from the Home tab's Slides group and select Reuse Slides. Click Browse in the Reuse Slides panel and select Browse Files. Double-click the PowerPoint presentation that contains the background you wish to copy. Check Keep Source Formatting and click the slide that contains the background you want. Click the left-hand slide preview to which you wish to apply the new master layout. Apply New Layout (Important): Right-click any selected slide, point to Layout, and click the slide containing the desired layout from the layout gallery. Delete any unwanted slides or duplicates. To copy the Customized Background from Another Presentation on Mac Click New Slide from the Home tab's Slides group and select Insert Slides from Other Presentation… Navigate to the PowerPoint presentation file that contains the background you wish to copy. Double-click or press Insert. This prompts the Slide Finder dialogue box. Make sure Keep design of original slides is unchecked and click the slide(s) that contains the background you want. Hold Shift key to select multiple slides. Apply New Layout (Important): Click Layout from the Home tab's Slides group, and click the slide containing the desired layout from the layout gallery. Robert Field JShell Architect Core Language and Tools Group Oracle Corporation October 4, 2017 Confidential – Oracle Internal/Restricted/Highly Restricted

3 This is a Safe Harbor Front slide, one of two Safe Harbor Statement slides included in this template. One of the Safe Harbor slides must be used if your presentation covers material affected by Oracle’s Revenue Recognition Policy To learn more about this policy, For internal communication, Safe Harbor Statements are not required. However, there is an applicable disclaimer (Exhibit E) that should be used, found in the Oracle Revenue Recognition Policy for Future Product Communications. Copy and paste this link into a web browser, to find out more information. For all external communications such as press release, roadmaps, PowerPoint presentations, Safe Harbor Statements are required. You can refer to the link mentioned above to find out additional information/disclaimers required depending on your audience. Confidential – Oracle Internal/Restricted/Highly Restricted

4 What is JShell? Tool providing a dynamic interaction with the Java™ programming language Read-Evaluate-Print Loop (REPL) for the Java™ platform Type in a snippet of Java code, see the results Deeply integrated with JDK tool-set Stays current and compatible Also, an API for use within other applications Dynamic interaction REPL – as seem, dynamic languages Snippet: expression, statement, or declaration Platform: in / built-on Showing command tool using technology. Encourage other tools built on API.

5 What is JShell NOT? Not a new language
“Snippets” of pure No new syntax Nothing added (except allowing snippets) Nothing removed (except things that don’t make sense…) Not a replacement for the compiler Not an IDE The point: interactive Java – not another language, not a mish-mash. Snippets: Java Language Specification productions For interactive exploration – compiler for programs Slippery slope for any language tool – integrate IDE

6 Who wants JShell? Exploring a new API or language feature
Experiment and instantly see results New to Java, new to programming Start with expressions vs classes Immediate feedback Prototyping Incrementally write complex code Now:: write class declaration, method declaration with access modifiers and array parameters, System.out.println JShell:: expressions & immediate see results We are all newbie – new APIs and language features Prototype seeing results at any granularity

7 Without JShell: Edit-Compile-Execute
Write a full program: Class Imports main method Cycle the whole program to understand if the behavior is correct: Edit Compiler or IDE Execute When want to try things out in Java now, you need it wrapped in main method and that wrapped in a class. You need imports for any libraries you are using. You need an editor of something to write the code, then compile it with command line tool or IDE, then execute it. For a whole program that is fine. For exploration that is slow.

8 Without JShell % cat Test.java import java.util.List; class Test {
  public static void main(String... args) {       List<String> alpha = List.of("Z", "A", "C");       alpha.sort(String::compareTo);       System.out.println( alpha );   } } % javac Test.java % java Test Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.ImmutableCollections.uoe(ImmutableCollections.java:70) at java.base/java.util.ImmutableCollections$AbstractImmutableList.sort(ImmutableCollections.java:85) at Test.main(Test.java:7) % This is a sample Title and Code Layout slide, ideal for displaying codes. To take advantage of the pre-formatted paragraph style: Start typing the code, using the tab key (not space key) to increase and Shift+tab keys to decrease indention levels for each paragraphs. Ignore the bullets at this point. If copy and paste the text from other sources, make sure the text is reset to the defaulted size and formatting by clicking Reset, within the Slides Group. (Or select Reset Layout to Default Settings, located at the bottom of the Layout gallery, for Mac.) Delete extra spaces. Once finish typing, select all text in the body copy block and click the Bullets button, within the Paragraph group to turn off bullets. Confidential – Oracle Internal/Restricted/Highly Restricted

9 Now in JShell…

10 Using the JShell tool With JDK 9 installed, type “jshell” at the command line The JShell tool takes two kinds of input: “Snippets” of Java code – declaration and execution JShell commands – information and control Commands are distinguished from snippets by leading slash: / All input can be tab completed, has history, and editing JShell evaluates “snippets” of Java code: an expression, statement, variable definition, method definition, class definition, or import.

11 Snippets Declarations: Statements: Not allowed:
String s = “hello” int twice(int x) { return x + x; } class Pair<T> { T a, b; Pair(… interface Reusable { } import java.nio.file.* Statements: while (mat.find()) { … if (x < 0) … switch (val) { case FMT: { format(); break; … Not allowed: package foo; Top-level modifiers: static final Top-level: break continue return Expressions: twice(12) new Pair<>("red", "blue") transactions.stream() filter(t -> t.getType() == Transaction.GROCERY) sorted(comparing(Transaction::getValue).reversed()) map(Transaction::getId) collect(toList()) Confidential – Oracle Internal/Restricted/Highly Restricted

12 Commands Snippet information: Snippet control: Session: History:
/list /vars /methods /types /imports Snippet control: /edit /drop /save /open Session: /exit /env /reset /reload History: /history /! /id /-n General: /set /help Confidential – Oracle Internal/Restricted/Highly Restricted

13 /list jshell> /help /li | | /list
| Show the source of snippets, prefaced with the snippet id. | List the currently active snippets of code that you typed or read with /open | /list -start | List the automatically evaluated start-up snippets | /list -all | List all snippets including failed, overwritten, dropped, and start-up | /list <name> | List snippets with the specified name (preference for active snippets) | /list <id> | List the snippet with the specified snippet id Confidential – Oracle Internal/Restricted/Highly Restricted

14 Completion / Information / Control
▷ -- snippet and command completion ▷ -- method parameters ▷ ▷ -- javadoc ⇧▷v -- expression to variable declaration ⇧▷i -- add import ^C -- interrupt running process or abort line ▷ == tab @ method( ⇧▷ == shift-tab ^C == Ctrl-C Confidential – Oracle Internal/Restricted/Highly Restricted

15 Line Editing (based on JLine 2.0)
Navigation ⏎ -- enters typed or history entry RETURN -- navigate line and history Editing – emacs/readline bindings ^A ^E ^L ^K ◆D ^Y ^R ^X ( -- move to start of line -- move to end of line -- clear screen -- kill rest of line -- kill word (Meta-D) -- yank: paste last killed text -- search history (reverse) -- begin keyboard macro Confidential – Oracle Internal/Restricted/Highly Restricted

16 Demo

17 JShell Guiding Principles
Compatibility: current and future Avoid chasing corner-cases Build on the platform (JDK) Easy and natural to use One size does not fit all (API) I've seen language tools that “cleverly” implemented functionality their own way, only to to be continually slightly out of sync, playing catch-up, and eventually falling too far behind. JShell built on and in the platform. API makes functionality available to any tool.

18 JShell Architecture Compilation: built on Compiler API
Execution: standard JVM controlled by Java Platform Debug Architecture All core functionality provided by JShell API. The jshell tool just one possible client. The jshell tool uses the popular jline2 API for command line interaction.

19 JShell module: JShell APIs, SPI, and library
Confidential – Oracle Internal/Restricted/Highly Restricted

20 JShell API An instance of JShell is the starting point. Doing an eval() of an input string returns SnippetEvents. Which hold several things, like value. But also created Snippets. Queries can be made for information about the Snippet. SourceCodeAnalysis provides information like completion. [API Demo?]

21 Meta-Demo

22 JDK 9 Information JShell released with JDK 9!
Download now: Documentation: Join the OpenJDK mailing lists: openjdk.java.net Follow us on and #Java9 Source code: hg.openjdk.java.net/jdk9/dev/ JShell now in JDK 9

23 JShell Documentation jshell tool tutorial “User Guide”:
jshell tool Reference: JShell APIs: JShell now in JDK 9

24 JShell Information JShell JEP: The Java Shell: JShell project / mailing list: JShell / my JShell now in JDK 9

25 The Team Engineering OpenJDK Commiters Documentation:
Robert Field Jan Lahoda OpenJDK Commiters Shinya Yoshida You? Documentation: Joni Gordon Advisors / Cheerleaders / Reviewers Brian Goetz Maurizio Cimadamore Joe Darcy Paul Sandoz Jonathan Gibbons Michel Trudeau Sundararajan Athijegannathan Rémi Forax Arun Gupta Mani Sarkar Daniel Daugherty Jan and I are the Oracle engineering team. Shinya Yoshida has contributed significantly as an OpenJDK Commiter, as could you, … The project was Brian's inspiration. Many people have advised, reviewed, and cheered us on.

26 Q & A

27 Stay connected Join us: DevOps Corner (Developer Lounge – Moscone West) Learn more: openjdk.java.net | wercker.com/java Follow: #JavaOne #DevOps

28 This is a Safe Harbor Front slide, one of two Safe Harbor Statement slides included in this template. One of the Safe Harbor slides must be used if your presentation covers material affected by Oracle’s Revenue Recognition Policy To learn more about this policy, For internal communication, Safe Harbor Statements are not required. However, there is an applicable disclaimer (Exhibit E) that should be used, found in the Oracle Revenue Recognition Policy for Future Product Communications. Copy and paste this link into a web browser, to find out more information. For all external communications such as press release, roadmaps, PowerPoint presentations, Safe Harbor Statements are required. You can refer to the link mentioned above to find out additional information/disclaimers required depending on your audience. Confidential – Oracle Internal/Restricted/Highly Restricted

29

30


Download ppt "JShell: An Interactive Shell for the Java Platform"

Similar presentations


Ads by Google