The easiest way I could think of would be to put all your error messages into an array and get them back by index. This would be a terrible way of doing it because if you change the order of eg. by adding one to the start of the array you'd have to go and make updates all through your code.
Is there a reason you don't just implement a properties file?
You might want to read from a file and add to a map. A properties file as mentioned before would do, or a simple text file. It's neat to have messages in a file so you can spellcheck or edit for consistent style and tone in one place.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Yes, they all works. But what happens if I (or rather, my clients) need to change my messages? They won't have access to my source codes or they don't have the slightest idea on how to compile a Java class.
The best is to use a properties file to keep the key & message. The properties file is a human-readable & understandable text file that can be easily altered. The best part is you don't need to touch your working codes.
Once you've the properties file, the array, map or enum methods can come in place.