why print("\0007") does not beep?

2.7k views Asked by At

I have tried this code on eclipse javaSE1.7, which is supposed to emit a beep, but it does not. Why is that?

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

source

3

There are 3 answers

1
Ingo On BEST ANSWER

There are many possibilities:

  1. You are not printing to a terminal.
  2. Someone removed the beeper from the terminal.
  3. your terminal emulation doesn't support beeps
  4. ... or it is turned off by some option
  5. your speakers are muted.
  6. ....

By the way, you are actually printing a NUL followed by '7'.

0
Elliott Frisch On

Not every font includes every character in the encoding (are you running it in an IDE console for example - that's probably also written in Java)? Anyway, that's not cross platform. What if your not on an ASCII machine?

public static void main(String args[]) {
  Toolkit.getDefaultToolkit().beep();
}
0
drequinox On

Try using beep method in JDK

import java.awt.*;
public class Beep {
  public static void main(String args[]) {
     Toolkit.getDefaultToolkit().beep();     
  }
}