
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How can we customize the start of JShell in Java 9?
JShell is an interactive REPL tool to execute and evaluate simple Java programs like variable declarations, statements, expressions, and etc.
When the JShell tool launched, the code has pre-loaded by default. To display this code, we just launch the command "/list -start". It is possible to ask JShell to load them automatically when it starts by using the command: "/set start [-retain] [Type]". The first option "-retain" tells JShell to record the desired [Type] startup for the next JShell sessions. If we don't specify it, the default startup can be launched when opening a new session
/set start [-retain] -File /set start [-retain] -Default /set start [-retain] -none
- /set start [-retain] File: This command tells JShell that when it starts, it must load the content of the file (this file contains code for creating variables, methods, classes, etc.).
- /set start [-retain] -none: This command tells JShell not to load any code/command when it starts.
- /set start [-retain] -Default: This command resets the start of JShell to its default value.
In the below code snippet, we can use "/set start [-retain] -File" command,
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.*; jshell> /set start -retain save.jsh jshell> /exit | Goodbye C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> /list -start s1 : int x = 20; s2 : double y = 30; s3 : public int sum(int a, int b) { return a + b; } s4 : String str = "TutorialsPoint";
In the below code snippet, we can use "/set start [-retain] -none" command.
jshell> /set start -retain -none jshell> /exit | Goodbye C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> /list -start
In the below code snippet, we can use " /set start [-retain] -Default" command.
jshell> /set start -retain -default jshell> /exit | Goodbye C:\Users\User>jshell | 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.*;
- Related Articles
- How can we implement a map in JShell in Java 9?
- How can we avoid compilation errors in JShell in Java 9?
- How can we execute snippets by ID in JShell in Java 9?
- How can we load a source code into JShell in Java 9?
- How can we import a gson library in JShell in Java 9?\n
- JShell in Java 9?
- How to debug JShell in Java 9?
- What are the rules we need to follow in JShell in Java 9?
- How to reset the JShell session in Java 9?
- Package Imports in JShell of Java 9
- Using Variables in JShell of Java 9
- How to modify the default editor of JShell in Java 9?
- How to get JShell documentation in Java 9?
- How to print the pattern of stars in JShell in Java 9?
- How to save the current JShell session in Java 9?
