This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Is there any way i can retrieve keys and values in the same order that i put. I am not sure why hashtable.keys() does not give the keys back in the same order and i dont understand the order in which it returns the keys.
I strongly advise you to find a tutorial on the Collections Framework. Any such tutorial worth its salt will explain the differences between different classes that implement the same interface. You should also familiarize yourself with the Java API documentation. First find the link to the documentation for the version of Java that you are using. Then to find the docs for a particular class, scroll the upper left frame down until you find the package that contains the class. In this case, all the Collection classes are in the java.util package. When you click on the package link, it loads the names of the classes in that package in the bottom left frame. Scroll until you find a class you want to learn more about, such as HashMap (notice the upper case M). When you click on the class name, the documentation for that class is loaded in the main frame on the right. This page gives a in-depth description of the class as well as a list of all non-private methods and fields. The list at the top gives links to more detailed descriptions further down the page. Learning to navigate this documentation is a crucial skill when programming Java, imo. It will help you find the differences between similar classes, such as those that you encountered above.