Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Performance and the fly likes System.properties or new  properties object for reading a .properties file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "System.properties or new  properties object for reading a .properties file?" Watch "System.properties or new  properties object for reading a .properties file?" New topic
Author

System.properties or new properties object for reading a .properties file?

Gaurav Kr. Arora
Ranch Hand

Joined: Feb 20, 2011
Posts: 37
Hi,

I am aware of two ways to read a .properties file:

1- System.getProperties.load(Inputstream for .properties file);

2- Creating a new Properties object and then calling load(Inputstream for .properties file);

In first approach, are we going to store values of .properties file in the System object. Is it utilizing more resources?

Would like to know which is the best way to do it or apart from above two ways, if there is any other best way, please let me know.

Thanks,
Vineet
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, if you want access to the system properties, you would do the former. If you just want a class to contain a set of properties and you don't need the system properties, you would do the latter. The choice is nothing to do with performance, the choice is whether you need to read the system properties or not.

And the difference between the two is likely to be trivial anyway.
Gaurav Kr. Arora
Ranch Hand

Joined: Feb 20, 2011
Posts: 37
Thanks a lot for the reply and clearing out the doubt! Is the System class of java has anything to do with my host machine?
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 200
    
    1

System Properties will tell you about the operating system, the user, the version of Java.... of the host machine.
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
Try loading the system properties and printing them (System.out.println(props)). Also there are other ways to load properties depending on what type of app you are running. For example xml files or for web apps the standard way you can load properties within web.xml etc. I like to abstract the way I am getting them from out of my code with an interface so I can change it without breaking my code.

As another poster stated there are no performance issues with any of the approaches.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: System.properties or new properties object for reading a .properties file?