CSS font stacks & developer FAQs with Web standards

WestNIC provides reliable web hosting services

Fastwebhost offers cheap web hosting & reseller hosting services

Site navigation below

This FAQ is part of the Code Style Help and FAQ section. Join our premium content service for full access all FAQ answers.

What if you were One Percent Better? Java ebooks for iPad, Kindle, Nook and Sony Reader

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 fulfills 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.

… full answer hidden

Premium members click below for full answer
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.

… full answer hidden

Premium members click below for full answer
How do I insert slashes in a date?

Q: How can I convert a String into a Date object?

A: The recommended way to parse a String representation of a date to a Date object is to use the java.text.SimpleDateFormat class parse(String) method. In its simplest form, the class is instantiated with a String pattern argument that defines the general syntax of the date to be parsed. In the example below, the World Wide Web Consortium (W3C) date time format for year, month and day is represented by the pattern yyyy-MM-dd and is used to parse the date string 2008-09-20.

… full answer hidden

Premium members click below for full answer
How can I convert a String into a Date object?

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.

… full answer hidden

Premium members click below for full answer
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.

… full answer hidden

Premium members click below for full answer
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).

Home · Web fonts · Font stacks · FAQs · Java · CSS · Javascript · HTML · Site manager