Thursday, 2 October 2014

Sound in Java

Structure of the Problem Requirements 

In this problem we will learn how to make a sound in Java program. Before this tutorial we upload program how to make sound in C++. In both case Beep function is used. In Java Beep exist in java.awt.Toolkit class. In this problem we used for loop and used a thread which play the sound continuously. Through Beep function beginners student can easily make a small security system which help them to understand it more clearly. Here is the source code of this problem which help you in better understanding.

Source Code 

package soundinjava;
import java.awt.Toolkit;
import java.util.Scanner;
public class sound {
public static void main (String args [])
int a;
Scanner input = new Scanner (;
System.out.println(" \t \t \t LEP TUTORIALS \n");
System.out.println(" Do You Want to Play Sound? \n");
System.out.println(" 1. Start \n");
a = input.nextInt();
if (a ==1)
for(int i = 0 ; i < 100; i++){
catch(Exception e)
System.out.print("Sorry Sound Can't Play ! \n \n ");

Output of the program

Beep function in java to create the sound
Beep function in Java

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

1 comments: Post Yours! Read Comment Policy!▼
Important Note:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

  1. Why are you using Threads ????
    Is there not working with out using threads ???
    For play sound just use the Beep simple if it is for beginners ??