Java JShell

JShell is the Java read-eval-print-loop (REPL) tool used for interacting quickly with Java from the command line without the need to compile and run.

Java JShell was introduced in Java 9 as project Kulla. Educators and experienced developers have long wanted a built in Java REPL, and finally we got it with JShell. JShell allows developers to test new coding concepts quickly without the cumbersom IDE environment previously associated with all rapid Java development.

JShell is a great learning for new developers and experienced developers that are just new to Java.

Continue reading “Java JShell”

Examining Libraries with JShell

Commonly, you want to use JShell to examine a 3rd-party libraries in JAR files. Some 3rd-party libraries are extremely well written, but hardly documented at all. That’s where having a Java REPL comes in handy. You can checkout the behavior of a library by putting the JAR it is in on the classpath for the Java REPL and then starting JShell.

For this tutorial, I have created a simple JAR library with two classes for testing from JShell. The tutorial explains how to use objects from libraries and static methods from libraries you want to test from inside JShell.

Continue reading “Examining Libraries with JShell”

Hello World, … First Java REPL Program

In this continuing JShell tutorial series for absolute beginner computer programmers, we do our first code in the form of two Hello World style examples. Make sure you check out the Java JShell Tutorial page where I have a list of the JShell Tutorials in this series in order.

So far, we’ve been looking at what the JShell is and why you would want to learn to program using the JShell. In this tutorial we’re going to have you doing a little simple programming.

Believe it or not, computer programmers have a lot of traditions. One of the most commonly followed traditions is to create a first program in any new language called, “Hello World!” In fact, even if the first program you write in a new language you are learning doesn’t print out “hello world,” the program is usually called a “hello world” program.

Continue reading “Hello World, … First Java REPL Program”

What is Java JShell

Thank you for stopping by my Java JShell tutorial site. This is one of an ongoing series of JShell tutorials about learning computer programming basics using JShell.

The first objective of this JShell tutorial is to explain what the JShell is.

JShell is a command line interface directed at anyone trying to learn Java programming. Tutorials usually have to start by explaining classes and objects, and return values and arguments, and on and on and on. This all just too much for the true beginner in the programming world.

JShell lets you type basic computer programming commands into the computer and see an immediate response. This allows tutoring in Java at a more remedial stage and not forcing  newbies to learn too much too fast.

Continue reading “What is Java JShell”

Why Java JShell Tutorials?

Finding the right programming tutorial is important. This one is about Java’s JShell. This Java JShell tutorial is designed to help absolute beginners get over the initial programming hump.

If you want to learn to program computers, phones, or refrigerators, there are several languages that will work for you. Java is one of the most respected languages and has been around for two decades. This means there are lots of tools to use with Java and lots of types of computers that can be programmed with Java.

Java, like most programming languages, can be difficult to begin to learn, just because you need to learn so much so fast just to do a simple program. That’s where JShell comes in. JShell makes the transition from knowing almost no Java to knowing enough to write programs much smoothing. Without JShell, taking the first steps into the Java programming world can be overwhelming.

Continue reading “Why Java JShell Tutorials?”

JShell Editing

Let’s say that while using JShell, perhaps even while doing one of the JShell Tutorials (nudge, nudge), you realize that you didn’t start JShell up with the print options turned on. Maybe you can’t even remember what options to use while starting JShell to get all the print methods.

No problem. You can add a print method just by typing in a method to wrap your favorite print method. My favorite print method is println() with one String argument, so I typed the following.

jshell> void println( String s ) {
   ...> System.out.println( s );
   ...> }
|  created method println(String)


Now you can use println() in your running instance of JShell even though you didn’t load JShell’s print methods on startup.

jshell> println( "Print me!")
Print me!


By the way, this tutorial has nothing to do with println() calls and everything to do with editing previously entered snippets.

Continue reading “JShell Editing”

JShell Static Imports

This tutorial focuses on using static imports with JShell. For the purposes of this JShell tutorial, we’ll stick with the java.lang.Math class. However, JShell can benefit from importing static methods and attributes from any class, not just java.lang.Math like in this tutorial.

Suppose you want to do some math quickly in JShell. You’ve just bought a new TV that is listed as 65.4 inches by 36.8 inches, but the company didn’t list the diagonal size of the screen. As you can imagine, this could cause you all kinds of embarrassment by not knowing the actual official size of the screen when you try to brag to your coworkers.

JShell to the rescue!

Continue reading “JShell Static Imports”

Quick JShell Introduction

Don’t have time for a full JShell tutorial? Here’s a very quick JShell overview that won’t eat up your time. Here’s the basics of Java’s JShell.

Java 9 introduced JShell to the Java world. JShell is what is called a REPL for the JVM. REPL stands for Read-Execute-Print-Loop. JShell allows you to execute snippets of Java code without writing a Java program and compiling it. You don’t even need to call the java command when using JShell.

Continue reading “Quick JShell Introduction”

JShell’s printf() Method

As everyone who’s anyone knows, Java 9 gave us JShell. JShell comes with printf() built in. However, you need to start JShell with the command jshell --start DEFAULT --start PRINTING to get printf() included. JShell’s printf() is the easiest way to format output for anything you happen to be using JShell for, and is especially nice if you are learning Java using JShell.

For example, suppose you want to print Pi out to five digits. Type the following into JShell.

printf("Pi is %.5f\n", Math.PI)

Not too surprisingly, that snippet prints out “Pi is 3.14159”. The mysterious %.5f tells JShell’s printf() to take the first argument to printf() after the string and display it at a floating point number with five decimal places.

There are tons of formatting tricks you can do with JShell’s printf(). First though, it is handy to understand the printf() method’s signature.

Continue reading “JShell’s printf() Method”

JShell … The Java 9 REPL

JShell, Java REPL introduced with Java 9, makes quick test code and simple Java snippets easy. Install Java 9, and you’ll have access to a shiny new JShell. If you’re using an early-access version on Mac OS X like I am, you’ll find JShell in the library hidden away in a path similar to the following.


Start up JShell on any OS and you’re presented with with the jshell> prompt. For JShell newBs, I recommend you start by typing /help at the JShell prompt to get a list of valid commands. Entering /help at the JShell prompt returns the following. Continue reading “JShell … The Java 9 REPL”