Skip to content

Java practice

Practice Java online: 10 exercises, graded problems and a playground

Your Java is compiled by a real javac and run inside your browser through TeaVM, which translates compiled Java into WebAssembly. That gives you genuine Java syntax, classes and the compiler's own error messages with nothing to install — with one honest limit: the class library is a subset, so the exercises stick to the parts a beginner meets first, and programs here do not read keyboard input.

checked exercises
10
graded problems
0
lessons
0
cheat sheet (coming)
0

Java practice exercises

How the path works →

In order, each one introducing a single new idea. Press Run to check your answer; hints open one at a time.

  1. Hello, Out LoudSystem.out.println prints a line, and a Java program always starts inside a main method
  2. Name TagA variable in Java has a fixed type, and String stores text under a reusable name
  3. Party PlannerJava splits division into two operators: / for whole groups, % for what's left over
  4. Umbrella or Notif/else chooses between two outcomes, and the test inside it must itself be true or false
  5. CountdownA for loop's own three parts, not a helper function, decide how it counts
  6. The Clapping GameAn if nested inside a for loop is decided again on every pass through the loop
  7. The ScoreboardString.format drops values into fixed-width slots so columns line up
  8. Packing ListArrayList holds a growable list of values, walked with a for-each loop
  9. Rainfall WeekA variable created above a loop carries a running value from one pass to the next
  10. The Cafe TicketAssembling a complete program from parts you already know

Coding interview questions

Original questions with full model answers, for when the practice is going somewhere specific.

Questions people ask

Is this a real Java compiler?
Yes — OpenJDK's javac compiles your source, and TeaVM runs the result in the browser. Compiler errors are the same ones you would see on your own machine; the difference is that not every class in the standard library is available.
Why is there no input box on the Java exercises?
The Java runtime used here does not read standard input yet, so the exercises put every value the program needs directly in the code. Reading with Scanner is covered in the Java guide for when you have a local JDK.
Do I have to write public static void main every time?
Yes, exactly as you would locally: each exercise is a complete class with a main method. Learning that shape early is deliberate, because every Java program you ever run starts there.
What should I practise after these exercises?
Beyond the 10 exercises: the coding interview questions, many of which are traditionally asked in Java.

Practise another language

The same kind of practice hub exists for Python, JavaScript, TypeScript, C++, C, C#, Go, PHP, Ruby, SQL, R and Bash & the Shell.