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:

Beep.java
				
					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:

Beep.java
				
					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.

Share it!

Facebook
Twitter
LinkedIn
Reddit
Picture of Ellion

Ellion

Professional IT consultant, writer, programmer enthusiast interested in all sorts of coding.
Eats all cookies 🍪

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x