Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a Hashtable and Properties?

Tags:

java

What is the difference between a Hashtable and Properties?

like image 314
billu Avatar asked Jun 08 '10 11:06

billu


People also ask

What is the difference between a Hashtable and a HashMap?

HashMap is non-syncronized and is not thread safe while HashTable is thread safe and is synchronized. HashMap allows one null key and values can be null whereas HashTable doesn't allow null key or value. HashMap is faster than HashTable. HashMap iterator is fail-safe where HashTable iterator is not fail-safe.

What are the properties of a class?

A class can have multiple properties. For example, objects classified as computers have the following properties: Hardware ID, Manufacturer, Model, and Serial Number. The data schema defines the structure in which properties are stored and organizes the properties into classes.

What is the difference between dictionary and Hashtable in Java?

Hashtable is a loosely typed (non-generic) collection, this means it stores key-value pairs of any data types. Dictionary is a generic collection. So it can store key-value pairs of specific data types.


2 Answers

Properties is a very specialized class that's designed to hold configuration and/or resources that are usually stored in some file.

It has several features that Hashtable doesn't have (and shouldn't have):

  • It supports reading and writing its content to a well-defined plain-text format (using load()/store())
  • It supports reading and writing its content to a well-defined XML-based format (using loadFromXML()/storeToXML())
  • It supports a default mechanism by providing another Properties instance at construction time.
  • It only supports String keys and values. While it is technically a Map<Object,Object> actually storing non-String keys or values is strongly discouraged and unsupported.

A Hashtable on the other hand is a general-purpose Map implementation (which is mostly replaced by the HashMap, however).

like image 187
Joachim Sauer Avatar answered Sep 20 '22 06:09

Joachim Sauer


Properties is a subclass of Hashtable, and it is designed for string to string mappings. It also adds the ability to store the mapping into a text file, and read it back.

like image 27
Eyal Schneider Avatar answered Sep 19 '22 06:09

Eyal Schneider