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:

  1. public - can accessed anywhere
  2. static - no need create instance
  3. final - since constants shouldnt allowed change
  4. 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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -