Forums Register Login

Which one is a good programming practice?

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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
My cellmate was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 509 times.
Similar Threads
File storing
Best Way to write application which can use different database
Static Final Variables Query
Whats Better? aving all constants in an interfce or having a separate constants file?
Beginner at Image manipulation...
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:03:29.