Java I/O How to - Make a beep by printing the ASCII Bell character to the console








Question

We would like to know how to make a beep by printing the ASCII Bell character to the console.

Answer


public class Main {
  public static void main(String args[]) {
    // ASCII bell
    System.out.print("\0007");
    System.out.flush();
  }
}

The code above generates the following result.