Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Properties and enumeration

 
divya madala
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain what is Properties?
what is enumeration?
What cases they are used?
Thanks for your help!!!
 
Sreenivasa Majji
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the usage, we use Properties object in our applet-servelet communication. When the applet needs to get some information from the server, we send a HTTP Query, then server responsds a Properties Object (in serialized form) to the applet. In side the calling method, we deseriazlie the object and get the Properties (key/value pair).
I haven't used Enumeration lately.
I think if you look at the API docs, you will understand what is Properties and Enumeration.
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "Properties" class is an extension of the "Hashtable" class. As such it is used to store key/value pairs. Later you can look up a value based on the key. It has a further capability of being able to retrieve its contents from a file formatted as such:

Generally the application [web or fat client] will load the properties file values at start-up and then use the property values to control aspects of the application (database connectivity, mail server names, etc.). If the property values are changed, the new values can easily be saved back out to a file.
Many applications use "Properties" instances to manage configuration. However there are other [newer] mechanisms for doing the same thing. You can use a "ResourceBundle" which does the same thing, but handles locale-specific encodings for you automatically.
As for "Enumeration", that is the 'old' way of looping through a collection, such as a "Properties" instance. The 'new' way is to use an "Iterator" instance, but if you're simply looking at the values either one will work.
You should check into the Sun Collections tutorial for additional details.
 
divya madala
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's informative. What does a System.getProperties()give?
 
Herb Schildt
Author
Ranch Hand
Posts: 253
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Wayne Johnson mentions above, Enumeration is a legacy interface that has been superceded by Iterator. It is not currently deprecated, but its use is usually considered obsolete for new code.
However, there is another type of enumeration to which you might be refering. The upcomming release of Java 2, v1.5 will be adding built-in support for enumerations, which are created using the new keyword enum. Both C and C++ support enum, but Java hasn't. With the release of 1.5, that will change.
The enum in Java will bear surface similarity to the enum supported by C/C++, but will be both more powerful and safer to use. This is a feature that many Java programmers have been looking forward to.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic