Sharing constant strings in Java across many classes? -
i'd have java constant strings @ 1 place , use them across whole project (many classes).
what recommended way of achieveing this?
public static final string constant_string="constant_string"; constants should be:
- public - can accessed anywhere
- static - no need create instance
- final - since constants shouldnt allowed change
- as per java naming convention should capitalized easy read , stands out in java documentation.
there instances interfaces used keep constants though don't see reason , considered bad practice create interface hold constants, approach keep in class makes more sense.
for e.g.
jframe has exit_on_close contant, class subclasses jframe have access , makes sense keep in jframe , not in jcomponent not components have option closed.
Comments
Post a Comment