
- 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 load a source code into JShell in Java 9?
JShell is an interactive tool for learning Java, and it is a REPL(Read-Evaluate-Print-Loop) that evaluates declarations, statements, and expressions.
While leaving a JShell session, we want to reuse the code previously entered into a new session. This can be done by using the command: /open [File_Path]. This command will load all code and internal commands found in file[File_Path] supplied as an option.
In the below code snippet, we can use the "/open [File_Path]" command to load source code from the directory with the ".jsh" extension.
C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> x | Error: | cannot find symbol | symbol: variable x | x | ^ jshell> y | Error: | cannot find symbol | symbol: variable y | y | ^ jshell> /list jshell> /open C:\Users\User\Desktop\save.jsh jshell> /list 1 : int x = 15; 2 : double y = 25.0; 3 : public int sum(int a, int b) { return a + b; } jshell> x x ==> 15 jshell> y y ==> 25.0 jshell> int result = sum(5, 7) result ==> 12
- Related Articles
- How to load a file into the JShell session in Java 9?
- 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 customize the start of JShell in Java 9?
- How can we import a gson library in JShell in Java 9?\n
- How can we execute snippets by ID in JShell in Java 9?
- How can we see the source code of a particular MySQL stored procedure?
- How can we see the source code of a particular MySQL stored function?
- JShell in Java 9?
- How to debug JShell in Java 9?
- How to implement a String in JShell in Java 9?
- How to create a thread in JShell in Java 9?
- How to get JShell documentation in Java 9?
- How to implement a lambda expression in JShell in Java 9?
- How to set a verbose mode in JShell in Java 9?

Advertisements