Java playground

Compile and run Java in your browser, without installing the JDK: one class per file, as in FP2, autocomplete with the methods of your classes and of String or ArrayList, and the compile error highlighted on its line. It is the environment of the website’s practical mock exams, now free for your own tests and exercises.

How to use it

  • Files: one tab per class. + creates a new one; the pencil (or a double click on its name) renames it and the cross deletes it (it asks for a second click). The classes see each other without import, as if they were in the same package.
  • Run compiles every file and runs the main of the open file; if that one has no main, the one of another class. If it does not compile, the error appears in the Console with its file and line, which is highlighted in the editor.
  • Input: what Scanner will read, one line per nextLine(). It is not interactive: type the data before running.
  • Your code is saved automatically in this browser. Download gives you the open class and .zip all of them, ready to open in IntelliJ or VS Code. Upload adds your own .java files.
  • Share creates a link with your code inside: whoever opens it sees your classes exactly as they are. The code travels inside the link itself; nothing is stored on the website.
  • Back to the sample restores the original classes (it asks for a second click). The expand button (top right) makes the environment fill the window and A− / A+ change the text size.

Keyboard shortcuts

ShortcutWhat it does
Ctrl + EnterCompiles and runs
Ctrl + SpaceShows the suggestions (sout writes System.out.println, main the main method and fori a for loop)
Tab or EnterAccepts the highlighted suggestion
Ctrl + /Comments or uncomments the selected lines
Ctrl + FFind and replace
Ctrl + Z and Ctrl + Shift + ZUndo and redo

On a Mac, Cmd instead of Ctrl.

What you can and cannot do

  • It compiles with javac (OpenJDK’s) and runs with TeaVM, all in WebAssembly inside your browser. You have everything in FP2: classes, inheritance, interfaces, exceptions, String, StringBuilder, Scanner, ArrayList, HashMap and the other collections.
  • The standard library is not complete: there are no threads, no files and no graphical interface.
  • An uncaught NullPointerException, an index outside an array or an infinite recursion stop the program, and the browser does not give the line: the environment tells you which exception it was.
  • The output appears when the program finishes, not while it runs. Each run can last at most 15 seconds.
  • The first time it downloads about 8 MB (the loading bar shows how it is going); after that it starts at once.

Practise with it

  • The exercises with solutions of Java in FP2: copy the statement, program it here and compare with the solution.
  • The solved programs: paste one, change it and see what happens.
  • If you are also learning Python, there is the Python playground, and more will arrive in Playgrounds.