Java playing sounds. Is there a default system sound?

user69514 picture user69514 · Mar 3, 2010 · Viewed 8.5k times · Source

Hi I am trying to write an application that will play morse code. I just wanted to know if there was a default system sound in java like some beep, or do I have to download some sound file from the internet?

Answer

rogeriopvl picture rogeriopvl · Mar 3, 2010

You can:

Print the ASCII bell character to the console (will emit a beep sound):

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

Use the beep() method that will use the buzzer on the motherboard:

import java.awt.*;

public class DoBeep {
    public static void main(String args[]) {
        Toolkit.getDefaultToolkit().beep();     
    }
}