8

Everything in Java seems to follow capitalization rules except for Hashtable.

Hashtable<String, String> ht = new Hashtable<String, String>();

as opposed to

ArrayList<String> a = new ArrayList<String>();

or

HashMap<String,Integer> a = new HashMap<String,Integer>(); 

Why is this ? Is Hash Table read as just one word (Hashtable) ?

Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103
  • 2
    How much technical this question is? Does having small "t" cause any issue (or) confusion? – kosa Sep 20 '12 at 05:48
  • The technicality I suppose is in using non suggestion editors for Java - invariably I end up writing HashTable because I am so used to following capitalization rules – Vrashabh Irde Sep 20 '12 at 05:53
  • 1
    @Nambari : Well this is perfectly valid question. Nominating to reopen – Nandkumar Tekale Sep 20 '12 at 06:10
  • 2
    more interestingly, why does C# have the same Hashtable? "http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx" – irreputable Sep 20 '12 at 16:14

2 Answers2

11

Hashtable was created in Java v1. The consistent naming conventions for collections were established later, in Java2, when the other classes were published as part of the brand new Java Collection Framework.

Which btw made Hashtable obsolete, so it should not be used in new code.

Hope that helps.

Bagira
  • 2,149
  • 4
  • 26
  • 55
1

Although this question has no technical value, I have to admit, I've asked myself this a couple of times :)

My version is that unlike List (ArrayList), Set (HashSet) , Map (Tree/HashMap) table is not a data structure.

Of course (its possibly known) that the Hashtable class was created before the collection framework (in java 1.0). So maybe at that point they didn't really thought about the same naming conventions. In general we better use collection framework from java 2+ :)

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
  • A map isn't a data structure? A hash table isn't a data structure? Non-data structure classes don't have to obey coding conventions? Please. – user207421 Sep 20 '12 at 08:55
  • I think you didn't get my point. Map IS a data structure (as a part of name HashMap and therefor can be capitalized). The same holds for Set (as a part of name HashSet, etc). But what about Hashtable? Does the word ''table'' denote a datastructure? Of course this is just my thoughts the whole thread is not technical, so as for me, some sort of speculation is allowed here :) – Mark Bramnik Sep 20 '12 at 09:58
  • "Does the word table denote a data structure?" It does to me, but even if it doesn't it still leaves the final question unanswered. – user207421 Sep 20 '12 at 10:38
  • Do you really expect a 'technically valid' answer of why t and not T ? :) As for the datastructure - remember the course in the university? I remember List, Queue, Tree, and so on. I don't remember table. Nevermind, I just thought that some flame and humor won't harm in this particular question, and you think different. Piece :) – Mark Bramnik Sep 20 '12 at 10:46