static.rainfocus.com...jshell> int age = 20 age ==> 20 jshell> age + 2 $2 ==> 22 jshell> 4 * $2 $3...
Transcript of static.rainfocus.com...jshell> int age = 20 age ==> 20 jshell> age + 2 $2 ==> 22 jshell> 4 * $2 $3...
EAD
VAL
RINT
OOP
# conventional ceremony
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
# jshell
jshell> System.out.println("Hello World")
Hello World
$ jshell
| Welcome to JShell -- Version 9
| For an introduction type: /help intro
jshell> /help
jshell> int age = 30age ==> 30
jshell> age = 31age ==> 31
jshell> int age = 29age ==> 29
jshell> /vars | /v| int age = 29
jshell> rate = 20| Error:| cannot find symbol| symbol: variable rate| rate = 20| ^--^
jshell> int rate = 20rate ==> 20
jshell> /list 2 : age = 31 3 : int age = 29; 4 : int rate = 20;
jshell> /list age 3 : int age = 29;
jshell> /list 3 3 : int age = 29;
jshell> /list -a | -all s1 : import java.io.*; ...
s10 : import java.util.stream.*;
1 : int age = 30; 2 : age = 31 3 : int age = 29; e1 : rate = 20 4 : int rate = 20;
jshell> int age = 20age ==> 20
jshell> age + 2$2 ==> 22
jshell> 4 * $2$3 ==> 88
jshell> "JavaOne 2017"$4 ==> "JavaOne 2017"
jshell> /list 1 : int age = 20; 2 : age + 2 3 : 4 * $2 4 : "Java 9 hack day"jshell> /34 * $2$5 ==> 88jshell> $3$3 ==> 88
jshell> /help
jshell> /help edit
jshell> /help /types
jshell> /help /set format
jshell> /imports
jshell> /impor
jshell> /impo
jshell> /imp
jshell> /im
jshell> /i
jshell> /r| Command: '/r' is ambiguous: /reset, /reload| Type /help for help.
jshell> Math.random()$8 ==> 0.1891103887126322
jshell> /!Math.random()$9 ==> 0.5946399311904251
jshell> /!Math.random()$12 ==> 0.6901639842319651
3 jshell> int age = 20; age ==> 202 jshell> Math.random() $2 ==> 0.93330752174562061 jshell> age = 21 age ==> 21
jshell> /-2Math.random()$5 ==> 0.6042322785203164
jshell> int sum(int first, int second) { return first + second;}| created method sum(int,int)
jshell> int mean(int first, int second) { return sum(first, second) / 2; }| created method mean(int,int)
jshell> /m | /methods| int sum(int,int)| int mean(int,int)
jshell> /m sum| int sum(int,int)
jshell> int mean(int first, int second) { return (first + second) / 2; }| modified method mean(int,int)
jshell> abstract class Figure { abstract double area(); }| created class Figure
jshell> class Dog { String name; Dog(String name) {this.name=name;} }| created class Dog
jshell> public enum Day {SUNDAY, MONDAY, TUESDAY, WEDNESDAY, ...}| created enum Day
jshell> /t | /type| class Figure| enum Day| class Dog
jshell> /type Day| enum Day
jshell> /t Figure| class Figure
jshell> /edit Figure | created class Circle
jshell> /t| class Figure| class Circle
jshell> /edit Figure | created class Rectangle
jshell> /types| class Figure| enum Day| class Dog| class Rectagle
jshell> /drop Dog| dropped class Dog
jshell> /t| class Figure| enum Day
jshell> /list Figure 2 : abstract class Figure { abstract double area(); }
jshell> /drop 2| dropped class Figure
jshell> /drop 2| This command does not accept the snippet '2' : abstract class Figure { abstract double area(); }
jshell> /type| enum Day| class Rectangle| which cannot be referenced until class Figure isdeclared
jshell> class Employee { ...> private String name; ...> ...> Employee(String name) { ...> this.name = name; ...> } ...> ...> String name() { ...> return name; ...> } ...> ...> }
| created class Employee
jshell> new Employee("Joe")$2 ==> Employee@2f686d1f
jshell> $2. <tab>equals() getClass() hashCode() name() notifyAll() notify() toString() wait()
jshell> $2.name()$3 ==> "Joe"
jshell> /list 1 : class Employee { private String name; private String surname;
Employee(String name, String surname) { this.name = name; this.surname = surname; } String name() { return name; } String surname() { return surname; } } 2 : Employee joe = new Employee("Joe","Doe")
jshell> /save employeeSnippets
jshell> /exit| Goodbye
$ lsemployeeSnippets
jshell> /list Employee 1 : class Employee { private String name; private String surname;
Employee(String name, String surname) { this.name = name; this.surname = surname; } String name() { return name; } String surname() { return surname; } } 2 : Employee joe = new Employee("Joe","Doe")
$ lsemployeeSnippets
$ jshelljshell> /open employeeSnippets
jshell> joe.name()$5 ==> "Joe"
jshell> joe.surname()$6 ==> "Doe"
jshell> /env -class-path mongo-java-driver-3.4.2.jar
| Setting new options and restoring state.
jshell> /env
| --class-path mongo-java-driver-3.4.2.jar
jshell> import com.mongodb.MongoClient
jshell> MongoClient mongoClient = new MongoClient()
jshell> String context = "JavaOne 2017"
context ==> "JavaOne 2017"
| created variable context : String
jshell> /list
1 : String context = "JavaOne 2017";
jshell> /reset
| Resetting state.
jshell> /list
jshell>
jshell> String context = "JavaOne 2017"
context ==> "JavaOne 2017"
| created variable context : String
jshell> /reload
| Restarting and restoring state.
-: String context = "JavaOne 2017";
jshell> /list
1 : String context = "JavaOne 2017";
# linux> /set editor /usr/bin/vim
# windows> /set editor c:\Program Files\NotePath\notepath.exe
# macOS> /set editor --wait open -a 'Sublime Text'
jshell> /set feedback
| /set feedback normal
|
| Available feedback modes:
| concise
| normal
| silent
| verbose
jshell> /set feedback verbose| Feedback mode: verbose
jshell> int age = 20age ==> 20| created variable age : int
jshell> /set feedback silent-> int age = 20->
$ jshell --startup PRINTING| Welcome to JShell -- Version 9| For an introduction type: /help intro
jshell> print("YAY!")YAY!
$ jshell --startup DEFAULT JAVASE PRINTING
$ jshell --startup DEFAULT JAVASE PRINTING
jshell> /exit
| Goodbye
jshell> /exi
| Goodbye
jshell> /ex
| Goodbye
jshell> CTRL + C + D
| Goodbye