Skip to main content

JShell Online (Java REPL)

Write JShell, press run and read the output in seconds. Nothing to install and nothing to configure.

How it works

Free, no install, works on laptop and phone.

What is an online JShell compiler?

An online JShell compiler is a free tool that lets you write JShell code in your browser and run it to see the output, with nothing to install. On Techsnap you can add input, run a program in seconds and use it on a laptop or a phone.

Updated December 2026

How to run JShell code online

  1. Step 1

    Write your JShell code

    Open the editor and type or paste your JShell program. Syntax colours and indentation help you spot mistakes as you go.

  2. Step 2

    Press Run

    Your code is sent to a secure server that compiles and runs it. Add any input the program needs in the Input box first.

  3. Step 3

    Read the output

    Results and error messages appear below the editor within a few seconds. Fix, edit and run again as often as you like.

Everything you need to code in JShell

Nothing to install

No JShell setup, PATH or version problems. It works on a college lab PC or a phone.

Input support

Give your program input the same way a judge or exam platform does, then check the output.

Instant results

Most runs finish in a second or two, so you can try an idea and see what happens right away.

Free to start

Run code without paying. A free Techsnap account gives you more runs and saves your work.

JShell code examples

Open the editor, paste one of these examples in and run it. Change a value and run it again to see what happens.

Hello World in JShell

System.out.println("Hello, Techsnap!");

Variables without a class

String name = "Asha";
int age = 21;
double marks = 87.5;
boolean passed = true;

System.out.println(name + " " + age + " " + marks + " " + passed);

If, else if and else

int marks = 72;

if (marks >= 90) {
    System.out.println("Grade A");
} else if (marks >= 60) {
    System.out.println("Grade B");
} else {
    System.out.println("Needs work");
}

Loops

for (int i = 1; i <= 3; i++) {
    System.out.println("for: " + i);
}

int n = 3;
while (n > 0) {
    System.out.println("while: " + n);
    n--;
}

Methods

int square(int x) {
    return x * x;
}

int add(int a, int b) {
    return a + b;
}

System.out.println(square(7));
System.out.println(add(5, 8));

Collections

import java.util.*;

List<Integer> nums = new ArrayList<>(List.of(4, 9, 12, 15, 20));
nums.add(25);
System.out.println(nums);

Map<String, Integer> marks = new HashMap<>();
marks.put("DSA", 90);
System.out.println(marks.get("DSA"));

Classes in a snippet

class Student {
    String name;
    int marks;
    Student(String name, int marks) { this.name = name; this.marks = marks; }
    String summary() { return name + " scored " + marks; }
}

Student s = new Student("Ravi", 78);
System.out.println(s.summary());

Streams and lambdas

import java.util.stream.*;

var squares = IntStream.rangeClosed(1, 5).map(n -> n * n).boxed().collect(Collectors.toList());
System.out.println(squares);

System.out.println(IntStream.rangeClosed(1, 10).filter(n -> n % 2 == 0).sum());

Records and var

record Point(int x, int y) {}

var p = new Point(3, 4);
System.out.println(p);
System.out.println(p.x() + p.y());

Exception handling

try {
    int age = Integer.parseInt("twenty");
    System.out.println(age);
} catch (NumberFormatException e) {
    System.out.println("Caught: not a number");
} finally {
    System.out.println("Done");
}

How to take input in JShell online

In a JShell script you can create a Scanner on System.in and read values the same way as in a Java program. Fill the Input box first.

import java.util.Scanner;

Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int total = 0;
for (int i = 0; i < n; i++) {
    total += sc.nextInt();
}
System.out.println("count: " + n);
System.out.println("sum: " + total);

Common JShell errors and how to fix them

error: cannot find symbol
A variable, method or class is not defined or is misspelled, or an import is missing. Declare it first or add the import.
error: incompatible types
A value of one type was assigned to another, such as a double to an int. Convert it with a cast.
error: ';' expected
A statement is missing its semicolon, though JShell lets you omit it on a final single line in interactive mode.
java.lang.NumberFormatException
A text value could not be turned into a number. Check the text, or wrap the conversion in try and catch.

Who uses an online JShell compiler

Students and learners

Practise JShell for class assignments and exams without installing anything.

Teachers and mentors

Share a short program in a lesson and let students run and change it on their own devices.

Interview candidates

Rehearse JShell questions in the same plain editor many online tests use.

Working developers

Check a snippet or an API behaviour in seconds without opening an IDE.

Writers and bloggers

Test code samples so the examples in your tutorials really run.

Teams

Paste a reproducible example into a ticket or chat so everyone sees the same result.

Online compiler vs local JShell setup

Techsnap online compilerLocal setup
Setup timeNone, open the pageInstall JShell, set PATH, pick a version
Works on any deviceYes, any modern browserOnly the machine you set up
Best forPractice, quick tests, learningLarge projects and long-running work
Extra librariesStandard library onlyAnything you can install

About JShell

What is JShell?

JShell is Java's interactive tool, called a REPL (read, evaluate, print, loop). It lets you type Java statements and expressions and see the result at once, with no class, no main method and no separate compile step.

What is JShell used for?

Learning Java, trying an API, testing a short snippet and teaching. It arrived in Java 9 and removes the boilerplate that makes first Java programs long.

JShell for beginners

You can write int x = 5; and use x on the next line. Methods and classes can be defined in the same session. The standard packages such as java.util are already imported.

JShell vs a normal Java program

A normal program needs a class with a main method and a compile step. In JShell the same code is just a few lines, which is better for experiments and learning.

Why use an online JShell?

JShell needs JDK 9 or later installed. An online JShell lets you try Java snippets from any device without installing the JDK.

JShell and Java careers

Java developers use it to explore libraries quickly. It is a good way to practise collections, streams and syntax before writing full classes.

Techsnap Java courses

Explore more online compilers

Frequently asked questions

Is this online JShell compiler free?

Yes. Write and run JShell code in your browser for free, with nothing to install. A free Techsnap account gives you more runs and saves your work.

Do I need a class and a main method?

No. That is the point of JShell: write statements, methods or classes directly and run them.

How do I take input in JShell online?

Use the Input box and read it with a Scanner on System.in, as shown on this page.

Can I run JShell on my phone?

Yes. The editor, input and output work in a mobile browser, so you can practise without a laptop.

Ready to write JShell code?

Open the editor and run your first program in under a minute.