• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which one is a good programming practice?  RSS feed

 
Sat Nar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
to store some constants,which one is a better way?Whether storing it in a property file and reading it through Properties() or storing it as some constants in a java file.I feel that reading a property file everytime will be having some impact on the performance.But at the same time,when we need to add new entries,if we store it in a class file,we need to change the source code.So which one is better?
 
Jass Singh
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sat Nar:
Hi,
to store some constants,which one is a better way?Whether storing it in a property file and reading it through Properties() or storing it as some constants in a java file.I feel that reading a property file everytime will be having some impact on the performance.But at the same time,when we need to add new entries,if we store it in a class file,we need to change the source code.So which one is better?


When you say constants, it means a value that is unlikely to change. So using constants in Java file is preffered approach and efficient as well.

Properties come into picture when you want to use some configurable values which can change frequently (e.g. DB URL, pwd, File Path etc).
It involves reading propeties file first time and getProperty() method call subsequently and hence it is not as fast as Constants.

So its upto you to decide as per your requirement.

Regards,
Jass
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!