Java visualizer new features in 2026

Summary

In 2026 we implemented a lot of new features and fixed long-standing limitations in Python Tutor's Java visualizer, including keyboard input with Scanner, visualizing Java collections, 2-D arrays, wrapper types, and upgrading from Java 8 to 25 with its simplified main, IO.println, and IO.readln. Most notably, it now runs Java 25 and is much faster than before.

Here's all the major new Java visualizer features we added in 2026. Most notably, it now runs Java 25 instead of Java 8, and it runs your code several times faster.

We recommend Java 25 since it has new features and is optimized to run faster than Java 8. Links made before this update now run on Java 25 too. If one of them doesn't look right (e.g., if it opens at a different step), you can still run Java 8 by clicking "Edit this code" and choosing "Java 8 (old version) [unsupported]".

For what the visualizer could already do, see How the Python Tutor visualizer can help students in your Java programming courses.

User input with Scanner

  • Programs can now read user input with Scanner (nextInt, nextLine, hasNextInt, etc). Your inputs are listed under "User inputs" for you to edit and re-run, and they're also saved in shared links. see it
  • Wrong input, like abc for nextInt(), shows an InputMismatchException on the line that read it, with the method calls that led there. see it

Newly-rendered data structures and objects

  • ArrayList, LinkedList, HashMap, TreeMap, LinkedHashMap, HashSet, TreeSet, and LinkedHashSet show their contents. Before, they were drawn as opaque labels like "ArrayList object". see it
  • Stack, ArrayDeque, and PriorityQueue show their contents, with the top of the stack, the front and back of the queue, and the head of the priority queue marked. Before, they were drawn as empty boxes. see it
  • StringBuilder shows its text. see it
  • 2-D arrays are drawn as grids instead of as an array of arrows to other arrays. (Uncheck "show array-of-arrays as 2D array" under the code editor to get the old view back.) see it
  • Wrapper types like Integer and Double are drawn as boxed values, so they look different from int and double. see it
  • BigInteger and BigDecimal show their values. see it
  • Exception objects show their message. see it

Java 25's simpler syntax for beginners

The visualizer now runs Java 25 (first released in 2025) by default. Most notably, it simplifies teaching by letting users write code without defining a class (it just needs a main method) and use IO.println to print. Other methods can go outside of any class too, like square here:

Here at Step 17, square(3) is about to return 9 to main, where total is 5 from the first two calls.

Similarly, IO.readln prints a prompt and reads one line of user input so users don't need to create a Scanner object:

Here at Step 2, IO.readln has read the first line the user typed, Ada, which is crossed out under "User input processed so far". Note that the output shows Ada after the prompt, as it would in a terminal. Then the next line reads 36 and crosses it out when the code has processed it.

Newer Java language features

The old Java 8 visualizer (released in 2014) couldn't run code that uses newer features of the language, but now Java 25 supports them. For instance:

  • var for local variables. see it
  • switch expressions with -> arrows. see it
  • Text blocks for strings that span several lines. see it
  • Records, which are drawn as objects with their fields. see it
  • Pattern matching with instanceof. see it
  • Sealed interfaces and switch on types, including record patterns. see it
  • Unnamed variables written as _. see it
  • Statements before super(...) in a constructor. see it
  • import module java.base; to import everything in one line. see it
  • Newer library methods such as List.of, getFirst, getLast, repeat, strip, isBlank, and stream().toList(). see it
  • Clearer exception messages from Java 25, such as Index 3 out of bounds for length 3 instead of just 3. see it

Fewer restrictions on how to write your code

  • The class with main doesn't need to be public. Before, the visualizer said "Make sure your code includes 'public class «ClassName»'". see it
  • Several public classes can go in one file, such as a textbook's BankAccount and BankAccountTest. Before, only one class could be public, so you had to delete public from the others. The first public class with a main method runs. see it
  • A package line at the top works now. Before, it gave a confusing "server may be overloaded" error. see it
  • Your own classes can be named Point, Stack, Queue, and so on. Before, these names clashed with an old Princeton library that came bundled with the visualizer. see it or a class named Stack.
  • import java.util.*; gives you Java's own Stack and Queue. Before, it gave you the Princeton library's versions instead, so code like Queue<String> line = new LinkedList<>(); didn't compile, and you had to write import java.util.Stack; and import java.util.Queue;. see it
  • main(String... args) and the other ways to write main that Java allows. see it
  • A missing import gets a hint, such as Add "import java.util.Scanner;" at the top of your file. see it

Java 8 is still available

If you need the old Java 8 choose "Java 8 (old version) [unsupported]" from the language menu. Programs that use the Princeton library (StdOut, StdIn, StdDraw, ...) need Java 8, since that library no longer comes with the visualizer.

Remaining limitations

  • Programs can't read files, start threads, or open windows or dialogs. see it
  • There's no way to signal the end of user input, so while (sc.hasNextLine()) keeps asking for more input. see it
  • What a program prints to System.err isn't shown. see it
  • Scanner, Random, Iterator, and some other library objects are drawn as empty boxes. see it
  • Variables don't show their declared types, only the type of the object they point to, so Animal pet = new Dog("Rex", 3); shows only a Dog. Fields don't show public, protected, or private either. see it
  • A class that extends a library class, like ArrayList, doesn't show its internal contents. see it
  • A NullPointerException doesn't say which variable was null. see it
  • Lambdas have names that the compiler made up, like lambda$main$0. see it

This article is part of the Python Tutor project (https://pythontutor.com)