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

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.

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

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.

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

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

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 :)

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

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.

Comments
Good Call
This article has been dead for over six months. Start a new discussion instead.