devxlogo

Emitting a Beep in Java

Emitting a Beep in Java

There are three ways to emit a beep in Java:

  1. Use an AU audio file: In Java, AU files need to be created at a sample rate of 8000. Higher sample rates will not work.
  2. Print the ASCII Bell character to the console, like this:
     public class testBeep {  public static main(String args[]) {     // ASCII bell     System.out.print("007");     System.out.flush();     }  }
  3. Starting with JDK 1.1, use the beep method in the Toolkit:
    import java.awt.*;public class beep {  public static void main(String args[]) {     Toolkit.getDefaultToolkit().beep();     }  }
    See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist