Make a beep sound in Java
problem
You wish to write a program that makes a beep sound. This is also know as the bell sound your Operating System does at times of warnings.
solution
Java comes out of the box with the AWT. It stands for Abstract Window Toolkit and it’s a library that we can use in this case and make a beep. For example:
Toolkit.getDefaultToolkit().beep();
The code above simply makes a beep.
We can place it in a main method in a class for easier execution as follows:
import java.awt.*;
public class BeepDemo {
public static void main(String[] args) {
Toolkit.getDefaultToolkit().beep();
}
}
conclusion
We just saw a simple way to make a beep sound in a Java program.