I happened to be working on a Java project recently where I needed to let the user save files through the GUI. The Swing toolkit has a nice JFileChooser class that lets you show a file save dialog so that the user can choose the directory and name of the file to save. However, not all filenames are valid, and Java doesn't validate them for you by default. If you try to save a file with an invalid name, Java will throw an error, and this is often considered the only way to know if the filename is valid. That's bad practice though since you should never rely on an exception being thrown as a condition of your program running correctly; by definition, exceptions are unreliable and sometimes unpredictable. Additionally if your file saves successfully then you have to immediately delete it (because you were only saving it to test the filename) and that's messy. So I wrote a ValidatedFileChooser class that checks various criteria to make sure that filenames are valid before attempting to save the file, and alerts the user if one of the criteria fails. The class is below, and I'm releasing it to the public domain.