Formatting dates in Java with DateFormat

By dave

There are several ways to format dates in Java, but by far the easiest is to use DateFormat. Creating a DateFormat is very similar to NumberFormat that we saw on the previous page. Here are the static factory methods called directly on the DateFormat class: getDateInstance(..) getDateTimeInstance(..) getTimeInstance(..) There are several overloaded versions of each method above. We will not cover...

The background, string formatting in java

By dave

Over the years there have been no shortage of ways to format a string in java. What with the + operator, , , and various specialised formatters for numbers and dates we sometimes feel a little spoilt for choice. But how do they all work and what are their advantanges / disadvantages? StringBuffer - a hang up from times gone...

Using Java's XMLStreamReader PULL XML Parser

By dave

In this entry I show how to use the inbuilt Java XMLStreamReader PULL parser class to read an XML file. The XML stream libraries are PULL based XML parsers that do not load the whole document into a memory structure, so therefore are more suited to large volumes of XML. Below is an example XML file for a zoo, it contains...

Formatting numbers using NumberFormat

By dave

is the class used to convert numeric values such as int, long and double into Strings. It has been around since the early days of Java, and generally performs well. Especially if you cache an instance of the class for repeated use. IMHO the only down side to using is that it can look a little verbose. To get...

These may be of interest

We use cookies to analyse traffic and to personalise content. We also embed Twitter and Youtube on some pages, these companies have their own privacy policies.

See the privacy policy and terms of use of this site should you need more information or wish to adjust your settings.