I have a list of constant strings that I need to display at different times during my Java program.
In C I could define the strings like this at the top of my code:
#define WELCOME_MESSAGE "Hello, welcome to the server"
#define WAIT_MESSAGE "Please wait 5 seconds"
#define EXIT_MESSAGE "Bye!"
I am wondering what is the standard way of doing this kind of thing in Java?
static final String WELCOME_MESSAGE = "Hello";
? – Oliver Charlesworth Mar 9 '12 at 18:21final
in Java means the reference can't be changed -- but the object it points to still might. Luckily for us,String
in Java is an immutable class, so afinal String
is const in both regards. – yshavit Mar 9 '12 at 19:01