• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constants vs Properties file  RSS feed

 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a bit confused between constants and properties file. When to go for Constants.java and when for .properties file?

Any help will be highly appreciated.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use constants you need to recompile your class, and probably every class that uses the constants as well because of inlining. With properties it's easier to change them since their values are not compiled into the classes but are only read at runtime. So if you expect your values to change, don't use constants.
 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:When you use constants you need to recompile your class, and probably every class that uses the constants as well because of inlining. With properties it's easier to change them since their values are not compiled into the classes but are only read at runtime. So if you expect your values to change, don't use constants.


Thanks Rob..that was really helpful
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!