how to play a clip of audio in java when needed

Java
Clip clip;

try {
	AudioInputStream input=AudioSystem.getAudioInputStream(new File("audio.wav"));
	clip=AudioSystem.getClip();
	clip.open(input);
	clip.start();
} catch (UnsupportedAudioFileException e) {
	e.printStackTrace();
} catch (IOException e) {
	e.printStackTrace();
} catch (LineUnavailableException e) {
	e.printStackTrace();
}AudioInputStream input = new AudioInputStream(Path_to_the_file);
Clip clip=AudioSystem.geClip();
clip.open(input);
Clip.loop(Clip.LOOP_CONTINUOSLY);
clip.start();
Source

Also in Java: