I’d like to have Java constant strings at one place and use them across whole project (many classes).
What is the recommended way of achieveing this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
constants should be:
There are instances where interfaces are used just to keep constants, but this is considered a bad practice because interfaces are supposed to define the behavior of a type.
A better approach is to keep it in the class where it makes more sense.
for e.g.
JFramehasEXIT_ON_CLOSEcontant, any class which subclassesJFramewill have access to it and it also makes sense to keep inJFrameand not inJComponentas not all components will have an option to be closed.