The Java language allows optional semicolons in a few places where they serve no purpose and can be distracting:

  • at the top level of a file, by JLS §7.6:

    class Test {
    };
    

    Extra “;” tokens appearing at the level of class and interface declarations in a compilation unit have no effect on the meaning of the compilation unit. Stray semicolons are permitted in the Java programming language solely as a concession to C++ programmers who are used to placing “;” after a class declaration. They should not be used in new Java code.

  • inside a class declaration, by JLS §8.1.7

    class Test {
      ;
    }
    
  • as an empty statement, by JLS §14.6

    class Test {
      void f() {
        ;
      }
    }
    

When a statement is required as the body of a control flow statement, for example an if or while, prefer using {} to ; for empty control flow statements. That is, prefer this:

while (true) {}

to this:

while (true) ;