You can try this example without actually having a remote server. To do so, simply
install all of the programs on the same machine, start rmiregistry, start AddServer, and
then execute AddClient using this command line:
java AddClient 8 9
Here, the address is the "loop back" address for the local machine. Using this
address allows you to exercise the entire RMI mechanism without actually having to install
the server on a remote computer.
In either case, sample output from this program is shown here:
The first number is: 8
The second number is: 9
The sum is: 17.0
Text Formatting
The package java.text allows you to format, search, and manipulate text. Chapter 32 illustrates
its NumberFormat class, which is used to format numeric data. This section examines two
more of its most commonly used classes: those that format date and time information.
DateFormat Class
DateFormat is an abstract class that provides the ability to format and parse dates and
times. The getDateInstance( ) method returns an instance of DateFormat that can format
date information. It is available in these forms:
static final DateFormat getDateInstance( )
static final DateFormat getDateInstance(int style)
static final DateFormat getDateInstance(int style, Locale locale)
The argument style is one of the following values: DEFAULT, SHORT, MEDIUM, LONG,
or FULL. These are int constants defined by DateFormat. They cause different details about
the date to be presented. The argument locale is one of the static references defined by Locale
(refer to Chapter 18 for details). If the style and/or locale is not specified, defaults are used.
One of the most commonly used methods in this class is format( ). It has several
overloaded forms, one of which is shown here:
final String format(Date d)
The argument is a Date object that is to be displayed. The method returns a string containing
the formatted information.
The following listing illustrates how to format date information. It begins by creating
a Date object. This captures the current date and time information. Then it outputs the date
information by using different styles and locales.
// Demonstrate date formats.
import java.text.*;
import java.util.*;
public class DateFormatDemo {
public static void main(String args[]) {
Date date = new Date();
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks