際際滷

際際滷Share a Scribd company logo
Scott Leberknight
1/12/2023
Jshell & ki
Jshell & ki
interactive command-line tools
REPL (read-evaluate-print-loop)
useful for learning & experimenting
JShell
write Java code interactively
introduced in JDK 9
create "snippets" of code
$ jshell
| Welcome to JShell -- Version 19
| For an introduction type: /help intro
jshell>
You type here :-)
Basics...
jshell> import java.time.*
jshell> var now = Instant.now()
now ==> 2023-01-12T02:47:48.336715Z
jshell> now.plusSeconds(15 * 60)
$6 ==> 2023-01-12T03:02:48.336715Z
jshell> var later = $6
later ==> 2023-01-12T03:02:48.336715Z
scratch variable
Tab completion
<press tab again to see documentation>
jshell> ZonedDateTime.
class from( now( of( ofInstant( ofLocal( ofStrict( parse(
jshell> ZonedDateTime.ofInstant(
$6 later now
Signatures:
ZonedDateTime ZonedDateTime.ofInstant(Instant instant, ZoneId zone)
ZonedDateTime ZonedDateTime.ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)
<press tab again to see documentation>
jshell> ZonedDateTime.ofInstant(
just keep pressing tab!
Show imports
jshell> /imports
| import java.io.*
| import java.math.*
| import java.net.*
| import java.nio.file.*
| import java.util.*
| import java.util.concurrent.*
| import java.util.function.*
| import java.util.prefs.*
| import java.util.regex.*
| import java.util.stream.*
| import org.kiwiproject.collect.*
| import com.google.common.collect.*
| import java.time.*
List snippets
jshell> /list
1 : import org.kiwiproject.collect.*;
2 : import com.google.common.collect.*;
3 : var m = KiwiMaps.<String, Object>newLinkedHashMap("a", 1, "b", 2, "c", 3);
4 : import java.time.*;
5 : var now = Instant.now();
6 : now.plusSeconds(15 * 60)
7 : var later = $6;
Rerun snippets
jshell> /list
1 : import org.kiwiproject.collect.*;
2 : import com.google.common.collect.*;
3 : var m = KiwiMaps.<String, Object>newLinkedHashMap("a", 1, "b", 2, "c", 3);
4 : import java.time.*;
5 : var now = Instant.now();
6 : now.plusSeconds(15 * 60)
7 : var later = $6;
jshell> /5
var now = Instant.now();
now ==> 2023-01-12T02:59:43.273136Z
jshell> /list 5
5 : var now = Instant.now();
jshell> now
now ==> 2023-01-12T02:59:43.273136Z
rerun snippet "5"
Many useful commands
work with snippets
(list, edit, drop, re-run, save to file, etc.)
open file as input source
list vars, methods, types, imports
set environment
(e.g. class & module path, configuration)
Accessing other code...
by default can access only JDK classes
use /env to set class and/or module path
Accessing other code...
jshell> /env -class-path .m2/repository/org/kiwiproject/kiwi/2.4.0/
kiwi-2.4.0.jar:.m2/repository/com/google/guava/guava/31.1-jre/guava-31.1-
jre.jar:.m2/repository/org/apache/commons/commons-lang3/3.12.0/commons-
lang3-3.12.0.jar
| Setting new options and restoring state.
jshell> import org.kiwiproject.collect.*
jshell> var m = KiwiMaps.<String, Object>newLinkedHashMap("a", 1, "b", 2, "c", 3)
m ==> {a=1, b=2, c=3}
set class (or module) path
Beware: you must supply all transitive dependencies!
uses Guava's Preconditions
Use verbose feedback
jshell> /set feedback verbose
jshell> ZonedDateTime.ofInstant(now, ZoneOffset.UTC)
$12 ==> 2023-01-12T02:59:43.273136Z
| created scratch variable $12 : ZonedDateTime
jshell> /set feedback normal
$ jshell -v
$ jshell --feedback verbose
start in verbose feedback mode
...or change within jshell
other feedback modes: concise, normal, silent
/help
Just remember...
/help is really good in jshell
you can learn a ton using it
be sure to use its tab completion
ki
Kotlin interactive shell
experiment with Kotlin or Java
much better than the default REPL
(i.e. kotlinc-jvm)
Accessing other code...
$ ki
ki-shell 0.5.2/1.7.0
type :h for help
[0] :dependsOn org.kiwiproject:kiwi:2.4.0
[1] import org.kiwiproject.collect.KiwiMaps
[2] val m : MutableMap<String, Int> = KiwiMaps.newHashMap("a", 1, "b", 2, "c", 3)
[3] m.put("d", 4)
res3: Int = null
[4] m
res4: MutableMap<String, Int> = {a=1, b=2, c=3, d=4}
Use :dependsOn with artifact coordinates:
groupId:artifactId:version
Yay!Transitive dependencies work!
:help
Just remember...
(alas, ki help is not as helpful as jshell's)
now get exploring and
remember /help
(or :help in ki)
On the web...
https://docs.oracle.com/en/java/javase/19/jshell/index.html
https://github.com/Kotlin/kotlin-interactive-shell
(the end)

More Related Content

Similar to JShell & ki (20)

Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017
Andres Almiray
?
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
JAX London
?
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017
Andres Almiray
?
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson
?
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 version
Schalk Cronj└
?
Spock
SpockSpock
Spock
Naiyer Asif
?
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
?
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developers
John Stevenson
?
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
Xavier Hallade
?
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
?
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
Tobias Oetiker
?
Developing with-devstack
Developing with-devstackDeveloping with-devstack
Developing with-devstack
Deepak Garg
?
2015.07.16 Способы диагностики PostgreSQL
2015.07.16 Способы диагностики PostgreSQL2015.07.16 Способы диагностики PostgreSQL
2015.07.16 Способы диагностики PostgreSQL
dev1ant
?
What we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan KrylovWhat we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan Krylov
J On The Beach
?
Clojure 1.1 And Beyond
Clojure 1.1 And BeyondClojure 1.1 And Beyond
Clojure 1.1 And Beyond
Mike Fogus
?
Inside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGInside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUG
Sylvain Wallez
?
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java Developers
Kostas Saidis
?
containerit at useR!2017 conference, Brussels
containerit at useR!2017 conference, Brusselscontainerit at useR!2017 conference, Brussels
containerit at useR!2017 conference, Brussels
Daniel N┨st
?
Java 9 preview
Java 9 previewJava 9 preview
Java 9 preview
Ivan Krylov
?
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: Gradle
Skills Matter
?
Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017
Andres Almiray
?
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
JAX London
?
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017
Andres Almiray
?
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson
?
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 version
Schalk Cronj└
?
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developers
John Stevenson
?
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
Xavier Hallade
?
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
?
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
Tobias Oetiker
?
Developing with-devstack
Developing with-devstackDeveloping with-devstack
Developing with-devstack
Deepak Garg
?
2015.07.16 Способы диагностики PostgreSQL
2015.07.16 Способы диагностики PostgreSQL2015.07.16 Способы диагностики PostgreSQL
2015.07.16 Способы диагностики PostgreSQL
dev1ant
?
What we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan KrylovWhat we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan Krylov
J On The Beach
?
Clojure 1.1 And Beyond
Clojure 1.1 And BeyondClojure 1.1 And Beyond
Clojure 1.1 And Beyond
Mike Fogus
?
Inside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGInside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUG
Sylvain Wallez
?
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java Developers
Kostas Saidis
?
containerit at useR!2017 conference, Brussels
containerit at useR!2017 conference, Brusselscontainerit at useR!2017 conference, Brussels
containerit at useR!2017 conference, Brussels
Daniel N┨st
?
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: Gradle
Skills Matter
?

More from Scott Leberknight (20)

JUnit Pioneer
JUnit PioneerJUnit Pioneer
JUnit Pioneer
Scott Leberknight
?
JDKs 10 to 14 (and beyond)
JDKs 10 to 14 (and beyond)JDKs 10 to 14 (and beyond)
JDKs 10 to 14 (and beyond)
Scott Leberknight
?
Unit Testing
Unit TestingUnit Testing
Unit Testing
Scott Leberknight
?
SDKMAN!
SDKMAN!SDKMAN!
SDKMAN!
Scott Leberknight
?
JUnit 5
JUnit 5JUnit 5
JUnit 5
Scott Leberknight
?
AWS Lambda
AWS LambdaAWS Lambda
AWS Lambda
Scott Leberknight
?
Dropwizard
DropwizardDropwizard
Dropwizard
Scott Leberknight
?
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
Scott Leberknight
?
httpie
httpiehttpie
httpie
Scott Leberknight
?
jps & jvmtop
jps & jvmtopjps & jvmtop
jps & jvmtop
Scott Leberknight
?
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
Scott Leberknight
?
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Scott Leberknight
?
Google Guava
Google GuavaGoogle Guava
Google Guava
Scott Leberknight
?
Cloudera Impala
Cloudera ImpalaCloudera Impala
Cloudera Impala
Scott Leberknight
?
iOS
iOSiOS
iOS
Scott Leberknight
?
Apache ZooKeeper
Apache ZooKeeperApache ZooKeeper
Apache ZooKeeper
Scott Leberknight
?
HBase Lightning Talk
HBase Lightning TalkHBase Lightning Talk
HBase Lightning Talk
Scott Leberknight
?
Hadoop
HadoopHadoop
Hadoop
Scott Leberknight
?
wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
Scott Leberknight
?
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
Scott Leberknight
?

Recently uploaded (20)

Revolutionizing Field Service: How LLMs Are Powering Smarter Knowledge Access...
Revolutionizing Field Service: How LLMs Are Powering Smarter Knowledge Access...Revolutionizing Field Service: How LLMs Are Powering Smarter Knowledge Access...
Revolutionizing Field Service: How LLMs Are Powering Smarter Knowledge Access...
Earley Information Science
?
16 KALALU????????????????????? APARAMAHASAHASRA SIMHAMAHANKALKIADIPARASAKTIBH...
16 KALALU????????????????????? APARAMAHASAHASRA SIMHAMAHANKALKIADIPARASAKTIBH...16 KALALU????????????????????? APARAMAHASAHASRA SIMHAMAHANKALKIADIPARASAKTIBH...
16 KALALU????????????????????? APARAMAHASAHASRA SIMHAMAHANKALKIADIPARASAKTIBH...
IT Industry
?
AMER Introduction to ThousandEyes Webinar
AMER Introduction to ThousandEyes WebinarAMER Introduction to ThousandEyes Webinar
AMER Introduction to ThousandEyes Webinar
ThousandEyes
?
Mastering ChatGPT & LLMs for Practical Applications: Tips, Tricks, and Use Cases
Mastering ChatGPT & LLMs for Practical Applications: Tips, Tricks, and Use CasesMastering ChatGPT & LLMs for Practical Applications: Tips, Tricks, and Use Cases
Mastering ChatGPT & LLMs for Practical Applications: Tips, Tricks, and Use Cases
Sanjay Willie
?
Benchmark Testing Demystified: Your Roadmap to Peak Performance
Benchmark Testing Demystified: Your Roadmap to Peak PerformanceBenchmark Testing Demystified: Your Roadmap to Peak Performance
Benchmark Testing Demystified: Your Roadmap to Peak Performance
Shubham Joshi
?
AI Trends and Fun Demos C Sotheby¨s Rehoboth Presentation
AI Trends and Fun Demos C Sotheby¨s Rehoboth PresentationAI Trends and Fun Demos C Sotheby¨s Rehoboth Presentation
AI Trends and Fun Demos C Sotheby¨s Rehoboth Presentation
Ethan Holland
?
SB7 Mobile Ltd: Simplified & Secure Services
SB7 Mobile Ltd: Simplified & Secure ServicesSB7 Mobile Ltd: Simplified & Secure Services
SB7 Mobile Ltd: Simplified & Secure Services
Reuben Jasper
?
Combining Lexical and Semantic Search with Milvus 2.5
Combining Lexical and Semantic Search with Milvus 2.5Combining Lexical and Semantic Search with Milvus 2.5
Combining Lexical and Semantic Search with Milvus 2.5
Zilliz
?
ISOIEC 42001 AI Management System 際際滷s
ISOIEC 42001 AI Management System 際際滷sISOIEC 42001 AI Management System 際際滷s
ISOIEC 42001 AI Management System 際際滷s
GilangRamadhan884333
?
Deno ...................................
Deno ...................................Deno ...................................
Deno ...................................
Robert MacLean
?
Kickstart Your QA: An Introduction to Automated Regression Testing Tools
Kickstart Your QA: An Introduction to Automated Regression Testing ToolsKickstart Your QA: An Introduction to Automated Regression Testing Tools
Kickstart Your QA: An Introduction to Automated Regression Testing Tools
Shubham Joshi
?
What is Blockchain and How Can Blockchain Consulting Help Businesses.pdf
What is Blockchain and How Can Blockchain Consulting Help Businesses.pdfWhat is Blockchain and How Can Blockchain Consulting Help Businesses.pdf
What is Blockchain and How Can Blockchain Consulting Help Businesses.pdf
Yodaplus Technologies Private Limited
?
Leadership u automatizaciji: RPA pri?e iz prakse!
Leadership u automatizaciji: RPA pri?e iz prakse!Leadership u automatizaciji: RPA pri?e iz prakse!
Leadership u automatizaciji: RPA pri?e iz prakse!
UiPathCommunity
?
10 FinTech Solutions Every Business Should Know!.pdf
10 FinTech Solutions Every Business Should Know!.pdf10 FinTech Solutions Every Business Should Know!.pdf
10 FinTech Solutions Every Business Should Know!.pdf
Yodaplus Technologies Private Limited
?
The Constructor's Digital Transformation Playbook: Reducing Risk With Technology
The Constructor's Digital Transformation Playbook: Reducing Risk With TechnologyThe Constructor's Digital Transformation Playbook: Reducing Risk With Technology
The Constructor's Digital Transformation Playbook: Reducing Risk With Technology
Aggregage
?
Caching for Performance Masterclass: The In-Memory Datastore
Caching for Performance Masterclass: The In-Memory DatastoreCaching for Performance Masterclass: The In-Memory Datastore
Caching for Performance Masterclass: The In-Memory Datastore
ScyllaDB
?
Webinar: LF Energy GEISA: Addressing edge interoperability at the meter
Webinar: LF Energy GEISA: Addressing edge interoperability at the meterWebinar: LF Energy GEISA: Addressing edge interoperability at the meter
Webinar: LF Energy GEISA: Addressing edge interoperability at the meter
DanBrown980551
?
2025-02-27 Tech & Play_ Fun, UX, and Community.pdf
2025-02-27 Tech & Play_ Fun, UX, and Community.pdf2025-02-27 Tech & Play_ Fun, UX, and Community.pdf
2025-02-27 Tech & Play_ Fun, UX, and Community.pdf
katalinjordans1
?
Big Data Analytics Quick Research Guide by Arthur Morgan (PREVIEW)
Big Data Analytics Quick Research Guide by Arthur Morgan (PREVIEW)Big Data Analytics Quick Research Guide by Arthur Morgan (PREVIEW)
Big Data Analytics Quick Research Guide by Arthur Morgan (PREVIEW)
Arthur Morgan
?
Temporary Compound microscope slide .pptx
Temporary Compound microscope slide .pptxTemporary Compound microscope slide .pptx
Temporary Compound microscope slide .pptx
Samir Sharma
?
Revolutionizing Field Service: How LLMs Are Powering Smarter Knowledge Access...
Revolutionizing Field Service: How LLMs Are Powering Smarter Knowledge Access...Revolutionizing Field Service: How LLMs Are Powering Smarter Knowledge Access...
Revolutionizing Field Service: How LLMs Are Powering Smarter Knowledge Access...
Earley Information Science
?
16 KALALU????????????????????? APARAMAHASAHASRA SIMHAMAHANKALKIADIPARASAKTIBH...
16 KALALU????????????????????? APARAMAHASAHASRA SIMHAMAHANKALKIADIPARASAKTIBH...16 KALALU????????????????????? APARAMAHASAHASRA SIMHAMAHANKALKIADIPARASAKTIBH...
16 KALALU????????????????????? APARAMAHASAHASRA SIMHAMAHANKALKIADIPARASAKTIBH...
IT Industry
?
AMER Introduction to ThousandEyes Webinar
AMER Introduction to ThousandEyes WebinarAMER Introduction to ThousandEyes Webinar
AMER Introduction to ThousandEyes Webinar
ThousandEyes
?
Mastering ChatGPT & LLMs for Practical Applications: Tips, Tricks, and Use Cases
Mastering ChatGPT & LLMs for Practical Applications: Tips, Tricks, and Use CasesMastering ChatGPT & LLMs for Practical Applications: Tips, Tricks, and Use Cases
Mastering ChatGPT & LLMs for Practical Applications: Tips, Tricks, and Use Cases
Sanjay Willie
?
Benchmark Testing Demystified: Your Roadmap to Peak Performance
Benchmark Testing Demystified: Your Roadmap to Peak PerformanceBenchmark Testing Demystified: Your Roadmap to Peak Performance
Benchmark Testing Demystified: Your Roadmap to Peak Performance
Shubham Joshi
?
AI Trends and Fun Demos C Sotheby¨s Rehoboth Presentation
AI Trends and Fun Demos C Sotheby¨s Rehoboth PresentationAI Trends and Fun Demos C Sotheby¨s Rehoboth Presentation
AI Trends and Fun Demos C Sotheby¨s Rehoboth Presentation
Ethan Holland
?
SB7 Mobile Ltd: Simplified & Secure Services
SB7 Mobile Ltd: Simplified & Secure ServicesSB7 Mobile Ltd: Simplified & Secure Services
SB7 Mobile Ltd: Simplified & Secure Services
Reuben Jasper
?
Combining Lexical and Semantic Search with Milvus 2.5
Combining Lexical and Semantic Search with Milvus 2.5Combining Lexical and Semantic Search with Milvus 2.5
Combining Lexical and Semantic Search with Milvus 2.5
Zilliz
?
ISOIEC 42001 AI Management System 際際滷s
ISOIEC 42001 AI Management System 際際滷sISOIEC 42001 AI Management System 際際滷s
ISOIEC 42001 AI Management System 際際滷s
GilangRamadhan884333
?
Deno ...................................
Deno ...................................Deno ...................................
Deno ...................................
Robert MacLean
?
Kickstart Your QA: An Introduction to Automated Regression Testing Tools
Kickstart Your QA: An Introduction to Automated Regression Testing ToolsKickstart Your QA: An Introduction to Automated Regression Testing Tools
Kickstart Your QA: An Introduction to Automated Regression Testing Tools
Shubham Joshi
?
Leadership u automatizaciji: RPA pri?e iz prakse!
Leadership u automatizaciji: RPA pri?e iz prakse!Leadership u automatizaciji: RPA pri?e iz prakse!
Leadership u automatizaciji: RPA pri?e iz prakse!
UiPathCommunity
?
The Constructor's Digital Transformation Playbook: Reducing Risk With Technology
The Constructor's Digital Transformation Playbook: Reducing Risk With TechnologyThe Constructor's Digital Transformation Playbook: Reducing Risk With Technology
The Constructor's Digital Transformation Playbook: Reducing Risk With Technology
Aggregage
?
Caching for Performance Masterclass: The In-Memory Datastore
Caching for Performance Masterclass: The In-Memory DatastoreCaching for Performance Masterclass: The In-Memory Datastore
Caching for Performance Masterclass: The In-Memory Datastore
ScyllaDB
?
Webinar: LF Energy GEISA: Addressing edge interoperability at the meter
Webinar: LF Energy GEISA: Addressing edge interoperability at the meterWebinar: LF Energy GEISA: Addressing edge interoperability at the meter
Webinar: LF Energy GEISA: Addressing edge interoperability at the meter
DanBrown980551
?
2025-02-27 Tech & Play_ Fun, UX, and Community.pdf
2025-02-27 Tech & Play_ Fun, UX, and Community.pdf2025-02-27 Tech & Play_ Fun, UX, and Community.pdf
2025-02-27 Tech & Play_ Fun, UX, and Community.pdf
katalinjordans1
?
Big Data Analytics Quick Research Guide by Arthur Morgan (PREVIEW)
Big Data Analytics Quick Research Guide by Arthur Morgan (PREVIEW)Big Data Analytics Quick Research Guide by Arthur Morgan (PREVIEW)
Big Data Analytics Quick Research Guide by Arthur Morgan (PREVIEW)
Arthur Morgan
?
Temporary Compound microscope slide .pptx
Temporary Compound microscope slide .pptxTemporary Compound microscope slide .pptx
Temporary Compound microscope slide .pptx
Samir Sharma
?

JShell & ki

  • 2. Jshell & ki interactive command-line tools REPL (read-evaluate-print-loop) useful for learning & experimenting
  • 3. JShell write Java code interactively introduced in JDK 9 create "snippets" of code
  • 4. $ jshell | Welcome to JShell -- Version 19 | For an introduction type: /help intro jshell> You type here :-)
  • 5. Basics... jshell> import java.time.* jshell> var now = Instant.now() now ==> 2023-01-12T02:47:48.336715Z jshell> now.plusSeconds(15 * 60) $6 ==> 2023-01-12T03:02:48.336715Z jshell> var later = $6 later ==> 2023-01-12T03:02:48.336715Z scratch variable
  • 6. Tab completion <press tab again to see documentation> jshell> ZonedDateTime. class from( now( of( ofInstant( ofLocal( ofStrict( parse( jshell> ZonedDateTime.ofInstant( $6 later now Signatures: ZonedDateTime ZonedDateTime.ofInstant(Instant instant, ZoneId zone) ZonedDateTime ZonedDateTime.ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) <press tab again to see documentation> jshell> ZonedDateTime.ofInstant( just keep pressing tab!
  • 7. Show imports jshell> /imports | import java.io.* | import java.math.* | import java.net.* | import java.nio.file.* | import java.util.* | import java.util.concurrent.* | import java.util.function.* | import java.util.prefs.* | import java.util.regex.* | import java.util.stream.* | import org.kiwiproject.collect.* | import com.google.common.collect.* | import java.time.*
  • 8. List snippets jshell> /list 1 : import org.kiwiproject.collect.*; 2 : import com.google.common.collect.*; 3 : var m = KiwiMaps.<String, Object>newLinkedHashMap("a", 1, "b", 2, "c", 3); 4 : import java.time.*; 5 : var now = Instant.now(); 6 : now.plusSeconds(15 * 60) 7 : var later = $6;
  • 9. Rerun snippets jshell> /list 1 : import org.kiwiproject.collect.*; 2 : import com.google.common.collect.*; 3 : var m = KiwiMaps.<String, Object>newLinkedHashMap("a", 1, "b", 2, "c", 3); 4 : import java.time.*; 5 : var now = Instant.now(); 6 : now.plusSeconds(15 * 60) 7 : var later = $6; jshell> /5 var now = Instant.now(); now ==> 2023-01-12T02:59:43.273136Z jshell> /list 5 5 : var now = Instant.now(); jshell> now now ==> 2023-01-12T02:59:43.273136Z rerun snippet "5"
  • 10. Many useful commands work with snippets (list, edit, drop, re-run, save to file, etc.) open file as input source list vars, methods, types, imports set environment (e.g. class & module path, configuration)
  • 11. Accessing other code... by default can access only JDK classes use /env to set class and/or module path
  • 12. Accessing other code... jshell> /env -class-path .m2/repository/org/kiwiproject/kiwi/2.4.0/ kiwi-2.4.0.jar:.m2/repository/com/google/guava/guava/31.1-jre/guava-31.1- jre.jar:.m2/repository/org/apache/commons/commons-lang3/3.12.0/commons- lang3-3.12.0.jar | Setting new options and restoring state. jshell> import org.kiwiproject.collect.* jshell> var m = KiwiMaps.<String, Object>newLinkedHashMap("a", 1, "b", 2, "c", 3) m ==> {a=1, b=2, c=3} set class (or module) path Beware: you must supply all transitive dependencies! uses Guava's Preconditions
  • 13. Use verbose feedback jshell> /set feedback verbose jshell> ZonedDateTime.ofInstant(now, ZoneOffset.UTC) $12 ==> 2023-01-12T02:59:43.273136Z | created scratch variable $12 : ZonedDateTime jshell> /set feedback normal $ jshell -v $ jshell --feedback verbose start in verbose feedback mode ...or change within jshell other feedback modes: concise, normal, silent
  • 15. /help is really good in jshell you can learn a ton using it be sure to use its tab completion
  • 16. ki Kotlin interactive shell experiment with Kotlin or Java much better than the default REPL (i.e. kotlinc-jvm)
  • 17. Accessing other code... $ ki ki-shell 0.5.2/1.7.0 type :h for help [0] :dependsOn org.kiwiproject:kiwi:2.4.0 [1] import org.kiwiproject.collect.KiwiMaps [2] val m : MutableMap<String, Int> = KiwiMaps.newHashMap("a", 1, "b", 2, "c", 3) [3] m.put("d", 4) res3: Int = null [4] m res4: MutableMap<String, Int> = {a=1, b=2, c=3, d=4} Use :dependsOn with artifact coordinates: groupId:artifactId:version Yay!Transitive dependencies work!
  • 18. :help Just remember... (alas, ki help is not as helpful as jshell's)
  • 19. now get exploring and remember /help (or :help in ki)