Java Reference
In-Depth Information
Chapter 5
Some Useful Classes
OBJECTIVES
• Describe the wrapper classes for primitive types.
• Describe classes String and StringBuffer .
• Describe classes Date and Vector .
• Describe how to format numbers.
• Describe random-number generation.
• Describe how to do input/output.
• Describe URLs and class URL .
INTRODUCTION
The packages of classes that come with Java enhance the basic language tremen-
dously. Here, we study a few of the classes that come with Java.
The wrapper classes allow us to handle values of primitive types as objects
of a class. For example, an Integer object contains, or “wraps”, an int value.
Classes String and StringBuffer provide strings of characters. Usually,
one uses String , but for maximum efficiency when performing some operations
on strings, it is best to use StringBuffer .
Class Vector provides for the maintenance of a list of objects. An instance
of class Date is a particular time —down to the millisecond.
Classes DecimalFormat and NumberFormat provide functions for formatting
numbers. For example, we may want decimal numbers to appear always with two
places following the decimal point, e.g. 4.56 . Class Locale provides number for-
mats for over 140 different “locales”: a locale is a country and a language.
Class Random provides functions for calculating “random” numbers. These
functions are useful in some games and in simulating various processes.
Reading from the keyboard and reading/writing files are not hard-wired into
Java. Instead, the ability to do IO (input/ouput) is provided by classes. We discuss
several ways of doing IO, as well as how to read from URLs.
Search WWH ::




Custom Search