954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Properties

Hi everyone,

I have a question about the use of properties.

You see usually if you wanted to add a property you would do this

Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost", proxy);
systemProperties.setProperty("http.proxyPort", port);


But the thing is i have heard now that this property class may be deprecated soon and people are now encouraged to use the ResourceBundle.

Here is the thing i am not very sure how to use the ResourceBundle class. I tried to yahoo but almost found no information on it. For example like the above code that i have, how does one convert that using the ResourceBundle class??

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West

freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
 

I doubt Sun will deprecate Properties.
After all, PropertyResourceBundle which is one of the main concrete ResourceBundle children uses it internally :)

public class PropertyResourceBundle extends ResourceBundle {
    /**
     * Creates a property resource bundle.
     * @param stream property file to read from.
     */
    public PropertyResourceBundle (InputStream stream) throws IOException {
        Properties properties = new Properties();
        properties.load(stream);
        lookup = new HashMap(properties);
    }


At the moment there's no way to get systemproperties through ResourceBundle, certainly not directly.
Conceivably this could of course be rewritten but I see little reason to.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Hi everyone,

I doubt Sun will deprecate Properties. After all, PropertyResourceBundle which is one of the main concrete ResourceBundle children uses it internally

That's true but i have been hearing rumours about it and i was afraid that they may deprecate it and actually even you said it at the below thread http://www.daniweb.com/techtalkforums/thread15732.html

At the moment there's no way to get systemproperties through ResourceBundle, certainly not directly


That's true as well there does not seem a way to get the system properties.

I asked this question because i use the Properties class quite a lot and was afraid that if they deprected it, i would have to do a lot of recoding and redesigning

Yours Sincerely

Richard West

freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
 

yes, there was some talk.
But mainly that's to do with using Properties to store localisation information.
That's what ResourceBundle was introduced for, to include generic support for multi-lingual environments.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Agree. ResourceBundle is designed for localization purpose. It is commonly used to localize text messages in an application, where a key name is assigned to a set of localized version of a specific text message. For information, see the second part of http://www.geocities.com/herong_yang/jdk/i18n.html .

Richard, an easy way to migrate your code away from the system properties is probably to create your own Properties object, call it like: mySystemProperties, and replace "= System.getProperties()" with "= mySystemProperties" everywhere in your code.

--Mark
http://www.geocities.com/herong_yang
Free Tutorial Books on Programming Technologies

mark1048
Newbie Poster
12 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

Hi everyone,

So basically you guys are saying that i have nothing to worry about as the Properties class probably won't be deprecated. Is that correct??

Richard West

freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
 

And if it is, there will be ample time to change your code to use whatever replaces it, given the lax attitude Sun takes towards removing deprecated material (they've never yet done it, there's stuff in there that was deprecated 9 years ago).
As it is you have no alternative for getting system properties anyway :)

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Hi everyone,

Sorry to ask this question but bear with me a while.

You see when you add a property to a program

for example say like that

Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost", proxy);
systemProperties.setProperty("http.proxyPort", port);


Basically my question is that does the property still remain even after the program is exited or do all the JVM properties simply go back to default

Any help is greatly appreciated

Yours Sincerely

Richard West

freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
 

You could test it of course by setting something in one program, then running another program to check whether that setting is still there :)

My GUESS is that they do persist, as the call can be influenced by a security manager. But I must admit I never tried it. If I need system props at all (usually file.separator, path.separator, and line.separator and little else) it's readonly.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You