We faced a similar problem. You are right that having messages in your code is a bad choice. We found that several factors influenced the best alternative. In our case, we needed to have the same error codes in Java on the client side, as well as in SQL and Perl code on the server side. We found it helpful to have a central definition, so we used a database.
If you need to handle error codes in Java, a property file or resource bundle is probably the most flexible as it allows localization and / or internationalization. I would stay away from the static class; although this is better than describing errors in a string, it is still relatively inflexible.
source share