जेशेल एक इंटरैक्टिव जावा शेल टूल है जो हमें शेल से जावा कोड निष्पादित करने में सक्षम बनाता है और तुरंत आउटपुट प्रदर्शित करता है। JShell REPL . है (रीड इवैल्यूएट प्रिंट लूप) टूल जो कमांड-लाइन . से चलता है . हम केवल "jshell" . लिखकर JShell प्रारंभ कर सकते हैं कमांड प्रॉम्प्ट में, और "/बाहर निकलें" . का उपयोग करके jshell से बाहर निकलने के लिए आज्ञा। छोटे स्निपेट के लिए, हमें मुख्य() . बनाने की आवश्यकता नहीं है JShell में विधि।
हम सूची . जैसे प्रमुख संग्रह भी लागू कर सकते हैं , मानचित्र और सेट इस उपकरण का उपयोग करके। नीचे दिए गए कार्यक्रम में, हम एक ArrayList . लागू कर सकते हैं विभिन्न परिदृश्यों के साथ।
उदाहरण
C:\Users\User\Desktop\Java 9 QNA>jshell
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro
jshell> ArrayList<String> list = new ArrayList<String>();
list ==> []
jshell> list.add("Jai");list.add("Adithya");list.add("Raja");list.add("Chaitanya");
$2 ==> true
$3 ==> true
$4 ==> true
$5 ==> true
jshell> list
list ==> [Jai, Adithya, Raja, Chaitanya]
jshell> list.isEmpty()
$7 ==> false
jshell> list.get(3)
$8 ==> "Chaitanya"
jshell> list.get(9)
| java.lang.IndexOutOfBoundsException thrown: Index 9 out-of-bounds for length 4
| at Preconditions.outOfBounds (Preconditions.java:64)
| at Preconditions.outOfBoundsCheckIndex (Preconditions.java:70)
| at Preconditions.checkIndex (Preconditions.java:248)
| at Objects.checkIndex (Objects.java:372)
| at ArrayList.get (ArrayList.java:440)
| at (#9:1)
jshell> list.size()
$10 ==> 4
jshell> if(list.isEmpty()) System.out.println("Empty"); else System.out.println("Not Empty");
Not Empty