What are the different startup scripts in JShell in Java 9?

JavaObject Oriented ProgrammingProgramming

JShell is an interactive Java Shell tool that executes code from the JShell and instantly displays an output. JShell is the REPL (Read-Evaluate-Print-Loop) tool that can run from the command-line prompt.

In JShell, there is an option to load a script on startup that includes some special predefined options. These can be specified using the "--startup" flag passing in either a filename or one of DEFAULT, JAVASE, and PRINTING. We can use "/list -start" comamnd to see all startup snippets to be evaluated.

  • DEFAULT: It loads the default behavior. This acts the same as if this is not specified at all.
  • JAVASE: It imports all Java SE packages by default.
  • PRINTING: It defines the functions print, println and printf for use.


In the below code snippet, we can use "DEFAULT" as a startup script.

C:\Users\User>jshell --startup DEFAULT
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro

jshell> /list -start

s1 : import java.io.*;
s2 : import java.math.*;
s3 : import java.net.*;
s4 : import java.nio.file.*;
s5 : import java.util.*;
s6 : import java.util.concurrent.*;
s7 : import java.util.function.*;
s8 : import java.util.prefs.*;
s9 : import java.util.regex.*;
s10 : import java.util.stream.*;


In the below code snippet, we can use "JAVASE" as a startup script.

C:\Users\User>jshell --startup JAVASE
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro

jshell> /list -start

s1 : import java.applet.*;
s2 : import java.awt.*;
s3 : import java.awt.color.*;
s4 : import java.awt.datatransfer.*;
s5 : import java.awt.desktop.*;
s6 : import java.awt.dnd.*;
s7 : import java.awt.event.*;
s8 : import java.awt.font.*;
s9 : import java.awt.geom.*;
s10 : import java.awt.im.*;
s11 : import java.awt.im.spi.*;
s12 : import java.awt.image.*;
s13 : import java.awt.image.renderable.*;
s14 : import java.awt.print.*;
s15 : import java.beans.*;
s16 : import java.beans.beancontext.*;
s17 : import java.io.*;
s18 : import java.lang.*;
s19 : import java.lang.annotation.*;
s20 : import java.lang.instrument.*;
s21 : import java.lang.invoke.*;
s22 : import java.lang.management.*;
s23 : import java.lang.module.*;
s24 : import java.lang.ref.*;
s25 : import java.lang.reflect.*;
s26 : import java.math.*;
s27 : import java.net.*;
s28 : import java.net.spi.*;
s29 : import java.nio.*;
s30 : import java.nio.channels.*;
s31 : import java.nio.channels.spi.*;
s32 : import java.nio.charset.*;
s33 : import java.nio.charset.spi.*;
s34 : import java.nio.file.*;
s35 : import java.nio.file.attribute.*;
s36 : import java.nio.file.spi.*;
s37 : import java.rmi.*;
s38 : import java.rmi.activation.*;
s39 : import java.rmi.dgc.*;
s40 : import java.rmi.registry.*;
s41 : import java.rmi.server.*;
s42 : import java.security.*;
s43 : import java.security.acl.*;
s44 : import java.security.cert.*;
s45 : import java.security.interfaces.*;
s46 : import java.security.spec.*;
s47 : import java.sql.*;
s48 : import java.text.*;
s49 : import java.text.spi.*;
s50 : import java.time.*;
s51 : import java.time.chrono.*;
s52 : import java.time.format.*;
s53 : import java.time.temporal.*;
s54 : import java.time.zone.*;
s55 : import java.util.*;
s56 : import java.util.concurrent.*;
s57 : import java.util.concurrent.atomic.*;
s58 : import java.util.concurrent.locks.*;
s59 : import java.util.function.*;
s60 : import java.util.jar.*;
s61 : import java.util.logging.*;
s62 : import java.util.prefs.*;
s63 : import java.util.regex.*;
s64 : import java.util.spi.*;
s65 : import java.util.stream.*;
s66 : import java.util.zip.*;
s67 : import javax.accessibility.*;
s68 : import javax.annotation.processing.*;
s69 : import javax.crypto.*;
s70 : import javax.crypto.interfaces.*;
s71 : import javax.crypto.spec.*;
s72 : import javax.imageio.*;
s73 : import javax.imageio.event.*;
s74 : import javax.imageio.metadata.*;
s75 : import javax.imageio.plugins.bmp.*;
s76 : import javax.imageio.plugins.jpeg.*;
s77 : import javax.imageio.plugins.tiff.*;
s78 : import javax.imageio.spi.*;
s79 : import javax.imageio.stream.*;
s80 : import javax.lang.model.*;
s81 : import javax.lang.model.element.*;
s82 : import javax.lang.model.type.*;
s83 : import javax.lang.model.util.*;
s84 : import javax.management.*;
s85 : import javax.management.loading.*;
s86 : import javax.management.modelmbean.*;
s87 : import javax.management.monitor.*;
s88 : import javax.management.openmbean.*;
s89 : import javax.management.relation.*;
s90 : import javax.management.remote.*;
s91 : import javax.management.remote.rmi.*;
s92 : import javax.management.timer.*;
s93 : import javax.naming.*;
s94 : import javax.naming.directory.*;
s95 : import javax.naming.event.*;
s96 : import javax.naming.ldap.*;
s97 : import javax.naming.spi.*;
s98 : import javax.net.*;
s99 : import javax.net.ssl.*;
s100 : import javax.print.*;
s101 : import javax.print.attribute.*;
s102 : import javax.print.attribute.standard.*
s103 : import javax.print.event.*;
s104 : import javax.rmi.ssl.*;
s105 : import javax.script.*;
s106 : import javax.security.auth.*;
s107 : import javax.security.auth.callback.*;
s108 : import javax.security.auth.kerberos.*;
s109 : import javax.security.auth.login.*;
s110 : import javax.security.auth.spi.*;
s111 : import javax.security.auth.x500.*;
s112 : import javax.security.cert.*;
s113 : import javax.security.sasl.*;
s114 : import javax.sound.midi.*;
s115 : import javax.sound.midi.spi.*;
s116 : import javax.sound.sampled.*;
s117 : import javax.sound.sampled.spi.*;
s118 : import javax.sql.*;
s119 : import javax.sql.rowset.*;
s120 : import javax.sql.rowset.serial.*;
s121 : import javax.sql.rowset.spi.*;
s122 : import javax.swing.*;
s123 : import javax.swing.border.*;
s124 : import javax.swing.colorchooser.*;
s125 : import javax.swing.event.*;
s126 : import javax.swing.filechooser.*;
s127 : import javax.swing.plaf.*;
s128 : import javax.swing.plaf.basic.*;
s129 : import javax.swing.plaf.metal.*;
s130 : import javax.swing.plaf.multi.*;
s131 : import javax.swing.plaf.nimbus.*;
s132 : import javax.swing.plaf.synth.*;
s133 : import javax.swing.table.*;
s134 : import javax.swing.text.*;
s135 : import javax.swing.text.html.*;
s136 : import javax.swing.text.html.parser.*;
s137 : import javax.swing.text.rtf.*;
s138 : import javax.swing.tree.*;
s139 : import javax.swing.undo.*;
s140 : import javax.tools.*;
s141 : import javax.transaction.xa.*;
s142 : import javax.xml.*;
s143 : import javax.xml.catalog.*;
s144 : import javax.xml.crypto.*;
s145 : import javax.xml.crypto.dom.*;
s146 : import javax.xml.crypto.dsig.*;
s147 : import javax.xml.crypto.dsig.dom.*;
s148 : import javax.xml.crypto.dsig.keyinfo.*;
s149 : import javax.xml.crypto.dsig.spec.*;
s150 : import javax.xml.datatype.*;
s151 : import javax.xml.namespace.*;
s152 : import javax.xml.parsers.*;
s153 : import javax.xml.stream.*;
s154 : import javax.xml.stream.events.*;
s155 : import javax.xml.stream.util.*;
s156 : import javax.xml.transform.*;
s157 : import javax.xml.transform.dom.*;
s158 : import javax.xml.transform.sax.*;
s159 : import javax.xml.transform.stax.*;
s160 : import javax.xml.transform.stream.*;
s161 : import javax.xml.validation.*;
s162 : import javax.xml.xpath.*;
s163 : import org.ietf.jgss.*;
s164 : import org.w3c.dom.*;
s165 : import org.w3c.dom.bootstrap.*;
s166 : import org.w3c.dom.events.*;
s167 : import org.w3c.dom.ls.*;
s168 : import org.w3c.dom.ranges.*;
s169 : import org.w3c.dom.traversal.*;
s170 : import org.w3c.dom.views.*;
s171 : import org.xml.sax.*;
s172 : import org.xml.sax.ext.*;
s173 : import org.xml.sax.helpers.*;


In the below code snippet, we can use "PRINTING" as a startup script.

C:\Users\User>jshell --startup PRINTING
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro

jshell> /list -start

s1 : void print(boolean b) { System.out.print(b); }
s2 : void print(char c) { System.out.print(c); }
s3 : void print(int i) { System.out.print(i); }
s4 : void print(long l) { System.out.print(l); }
s5 : void print(float f) { System.out.print(f); }
s6 : void print(double d) { System.out.print(d); }
s7 : void print(char s[]) { System.out.print(s); }
s8 : void print(String s) { System.out.print(s); }
s9 : void print(Object obj) { System.out.print(obj); }
s10 : void println() { System.out.println(); }
s11 : void println(boolean b) { System.out.println(b); }
s12 : void println(char c) { System.out.println(c); }
s13 : void println(int i) { System.out.println(i); }
s14 : void println(long l) { System.out.println(l); }
s15 : void println(float f) { System.out.println(f); }
s16 : void println(double d) { System.out.println(d); }
s17 : void println(char s[]) { System.out.println(s); }
s18 : void println(String s) { System.out.println(s); }
s19 : void println(Object obj) { System.out.println(obj); }
s20 : void printf(java.util.Locale l, String format, Object... args) { System.out.printf(l, format, args); }
s21 : void printf(String format, Object... args) { System.out.printf(format, args); }
raja
Published on 15-Apr-2020 13:50:12
Advertisements