JShell Java भाषा सीखने और Java कोड प्रोटोटाइप करने के लिए एक इंटरैक्टिव टूल है। यह एक REPL (Read-Evaluate-Print-Loop) है जो दर्ज किए गए घोषणाओं, स्टेटमेंट्स, और एक्सप्रेशंस का मूल्यांकन करता है और तुरंत JShell में परिणाम प्रिंट करता है। यह टूल कमांड-लाइन प्रॉम्प्ट से चलता है।
मॉडिफायर जैसे public, protected, private, static, और final को शीर्ष-स्तरीय घोषणाओं पर अनुमति नहीं है और चेतावनी के साथ अनदेखा किया जा सकता है। कीवर्ड जैसे synchronized, native, abstract, और default top-level मेथड्स की अनुमति नहीं है और वे त्रुटियां हो सकते हैं।
नीचे दिए गए कोड स्निपेट में, हमने final और static वेरिएबल दोनों बनाए हैं। यह उपयोगकर्ता को एक चेतावनी संदेश प्रिंट करता है कि "Modifier 'final' or 'static' not permitted in top-level declarations, ignored"।
उदाहरण-1
C:\Users\User\>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> final int x = 0 | Warning: | Modifier 'final' not permitted in top-level declarations, ignored | final int x = 0; | ^---^ x ==> 0 jshell> x = 1 x ==> 1
उदाहरण-2
jshell> static String str = "Tutorix" | Warning: | Modifier 'static' not permitted in top-level declarations, ignored | static String str = "Tutorix"; | ^----^ str ==> "Tutorix"