Properties

F

freesoft_2000

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
 
C

Chris Smith

freesoft_2000 said:
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);

Specifically, that's called adding a system property. System properties
are a tiny part of the usage of the java.util.Properties class. Most
uses of properties involve loading properties files that are included as
resources within an application.
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.

I don't know where you heard this, but there are a few possibilities.

1) Your source could have been wrong.

2) Some people (confusingly) refer to any API for which some use is
discouraged as "deprecated". It's quite possible that Sun will more
strongly emphasize the need to use proper internationalization in
applications that store text messages to be displayed to the user. If
so, they will probably discourage most common uses of the Properties
class.

3) If Properties is deprecated at some point in the future, then most
likely Sun will add an alternative at the same time they deprecate it.
For example, it may be that Sun will add a System.getPropertyMap() that
returns a Map<String, String>. Frankly, this would make more sense
anyway, since the fuctionality of the Properties class is primary
concerned with saving and loading properties to/from streams. With
generics, there remains no good reason to use the Properties class for
system properties.
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??

You don't. ResourceBundle is for application-level properties. It's
designed so that the values can be customized based on the current
locale. It doesn't do the stuff you're doing above.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Andrew Thompson

But the thing is i have heard now that this property class may be
deprecated soon ..

What makes you say that? There is no indication of it in
the 1.5 JavaDocs.
<http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html>

The only method marked as deprecated is ..
<http://java.sun.com/j2se/1.5.0/docs...#save(java.io.OutputStream, java.lang.String)>
...and only because it was coded to swallow exceptions.

A couple of notes.

Sun may be slack with annotating the @since tags on
classes, methods and attributes, but they are much
more rigorous about documenting @deprecation.

Further, the rather irritating 'show()' method, deprecated
in 1.1, is still alive and healthy in the 1.5 JRE.

I suspect you do not have to worry about the disappearance
of the Properties class any time soon. In fact, I think
you might be porting the code to a 'more advanced'
language before it happens.

Ultimately though, the best solution for your data is..
not clear. What exactly are you trying to store, what
sorts of sizes etcetera? And for what purpose(s)?
 
F

freesoft_2000

Hi everyone,

Yes i think chris you are right that maybe my source could
be wrong. To answer andrew's question i heard that the deprecation maybe
started in sdk 1.7 and the type of data i am trying to store are simple
networking proxies of the same size of the code i posted in my first post

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 properties simply go back to default

Any help is greatly appreciated

Yours Sincerely

Richard West
 
A

Andrew Thompson

..the type of data i am trying to store are simple
networking proxies of the same size of the code i posted in my first post

Good. Not needing anything complex, and relatively small
amounts of data, the options are wide open, but I suspect
this task is well suited to a properties file.
Basically my question is that does the property still remain even after
the program is exited or do all the properties simply go back to default

<a little exasperated>
...did you check the first line of the JavaDocs in relation
to the Properties class? Was there anything in that sentence
that was unclear to you?
</a little exasperated>
 
F

freesoft_2000

Hi everyone,

Andrew, this is what it says in the first line

"The Properties class represents a persistent set of properties."

I find it a bit vague but if i were to guess i think that these properties
remain even after the application has exited??

Am i right??

Hoping to hear from you

Richard West
 
A

Andrew Thompson

Andrew, this is what it says in the first line

"The Properties class represents a persistent set of properties."

<google tip>
<http://www.google.com/search?q=definition+persistent>
</google tip>

Does that answer you question (and potentially others,
especially in relation to word meanings)?

[ ..and something I forgot to add before was,
How many line of code do you think it would take to
actually test this? I suspect it could be done in
around 50-60 lines. ..But the docs are (usually)
quicker. ]
 
F

freesoft_2000

Hi everyone,

I know that these properties are persistant. But my
question is do these properties still persist even after the program that
added these properties has already exited.

The docs do say that they are persistant but they do not
say if the persistance only occurs in the program that added that
properties or do the properties still exist after the program has exited.

I really need clarification for this

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
A

Andrew Thompson

I know that these properties are persistant.

persistEnt.. If you had googled that, Google would
suggest the different spelling.
...But my
question is do these properties still persist even after the program that
added these properties has already exited.

Describe to me in simple terms.

[1] What does 'persist' *mean* to you?
Fill in this sentence 'The meaning of the word persistence is..'

The first four or five hits on the search were pretty indicative
of the entire concept that Sun is trying to get across in the
docs.
The docs do say that they are persistant but they do not
say if the persistance only occurs in the program that added that
properties or do the properties still exist after the program has exited.

See [1].
I really need clarification for this

I really need an asprin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,262
Messages
2,571,049
Members
48,769
Latest member
Clifft

Latest Threads

Top