World class Hard Drive Recovery and renowned raid recovery services

WestNIC provides reliable web hosting services

Site navigation below

This FAQ is part of the Code Style Help and FAQ section. Use the help request form below if your question is not answered here, but make sure you are asking the right question first.

Subscribe to this FAQ: RSS news feed

FAQ search

Storage structures

Q: What is the first argument in the Hashtable put() method?

A: You should download the Java API documentation, which details all standard classes and their method parameters. The first parameter in a Hashtable's put method is the key by which the value in the second argument will be stored.

To retrieve the stored value, use the get(Object) method, where the object parameter is a reference to the key.

Q: What is the difference between Hashtable and HashMap?

A: In Java 2 Hashtable fulfils the Map interface like HashMap. The main difference between Hashtable and HashMap is that HashMap is not synchronized and allows a null key to be used and null values to be stored.

Premium Content: Follow this link for subscription information More details available to subscribers:
What is the difference between Hashtable and HashMap?

Q: How do I get the keys from a Map?

A: To get the keys in a map rather than the values, use the keySet() method, which returns a java.util.Set object that contains all the keys. You can then get an Iterator from the key set, or process the keys using other Set methods.

Q: Why is Vector a legacy class?

A: Vector is a legacy class that was adapted in Java Software Development Kit version 1.2 to integrate it with the more contemporary collections framework. Vector now implements the Collection interface.

Working with dates and calendars

Q: How do I insert slashes in a date?

A: To format Date types in Java, you should use a java.text.SimpleDateFormat. This class takes a time pattern string and applies it to the given date like a template. To create a date with slashes, you might use the pattern "dd/MM/YYYY" for instance.

Premium Content: Follow this link for subscription information More details available to subscribers:
How do I insert slashes in a date?

Q: How can I get the difference between two dates in days?

A: To compare dates by day, deduct the millisecond time of the earlier date from the later one and divide the result by the number of milliseconds in a day. This method checks the dates are not the same and uses the after(Date) method to check the deduction is the right way round. For finer comparisons by hour or minute, it is important to check any possible timezone offset too.

Premium Content: Follow this link for subscription information More details available to subscribers:
How can I get the difference between two dates in days?

Q: Why isn't my custom Calendar class called?

A: If you have a broad import statement like import java.util.*;, the Java Virtual Machine will adopt the standard distribution version of any named class, such as java.util.Calendar. You should limit the scope of your import statements and use the fully qualified name of the custom Calendar class.

Premium Content: Follow this link for subscription information More details available to subscribers:
Why isn't my custom Calendar class called?

Q: Why do we use Calendar.getInstance()?

A: The Calendar class is abstract and instances must be obtained from the static getInstance() method so that they are created with an appropriate locale. Calendars must be created with a specific Locale reference to take account of regional time zones and any seasonal daylight saving changes when getting dates, including AM or PM values and time relative to Greenwich Meantime (GMT).

Help request

Use the form below to submit a help request or general enquiry about the Code Style Web site. Read our guidelines on asking the right questions first.

Information: Your email address will not be mis-used. If you include your address you may be sent a personal reply, you will not be added to any mailing list unless you request it. Read the site privacy statement for details.

Add this page to your chosen social bookmarking service

Style warning - please read

Home · CSS · Java · Javascript · HTML · Help · Log