While MP3 encoding support in Java Sound is nonexistent, you will need 3rd party libraries for doing so. This post will talk about the necessary requirements to convert, say, a WAV file to MP3 format under a Windows environment as the encoding files involved are DLL files. If you are in some other operating system, check the readme files included in the zip files.
A good library to use is Tritonus, which is an implementation of the Java Sound API. You need these two files: tritonus_mp3.jar and tritonus_share.jar which is a shared classes required by all other Tritonus plug-ins. You can add these two files in the JDK and/or JRE’s library extension folder or you can include them in the classpath of your project.
To make use of Tritonus’ libraries to encode to MP3 format, go to their site’s plugin page and download the file tritonus-mp3enc-2001-04-25.zip under mp3 Encoder. That zip file contains a sample java source code for encoding to MP3 format as well as instructions on where to place the included lametritonus.dll (since it is windows, it should be placed in c:\windows\system32).
The other requirement is equally important, called LAME. It is a high quality MPEG Audio Layer III (MP3) encoder licensed under the LGPL. The DLL for this is responsible for the encodings. Download the LAME package and transfer the DLL file lame_enc.dll to c:\windows\system32.
You can get it in http://www.jthz.com/~lame/.
That is it. You can then check if your conversion from WAV to MP3 works by compiling and running the Mp3Encoder.java source file. Keep in mind that those two DLL files are very important so they must both be present.