3. Basics
What is a util?
The util (also frequently used in plural as utils) is the common
textbook/classroom unit used to discuss the utility derived from consumption.
What is a utility class?
In computer programming, a utility class is a class that defines a set of methods
that perform common, often re-used functions. Most utility classes define these
common methods under static scope.
4. String Tokenizer
The java.util.StringTokenizer class allows an application to break a string into
tokens.
This class is a legacy class that is retained for compatibility reasons although its
use is discouraged in new code.
Its methods do not distinguish among identifiers, numbers, and quoted strings.
This class methods do not even recognize and skip comments.
*StringTokenizer class is deprecated now. It is recommended to use split() method of String class or regex (Regular
Expression).
5. Continue
A StringTokenizer object internally maintains a current position within the string to
be tokenized. Some operations advance this current position past the characters
processed.
A token is returned by taking a substring of the string that was used to create the
StringTokenizer object.
8. Date
The java.util.Date class represents a specific instant in time, with millisecond
precision.
Although the Date class is intended to reflect coordinated universal time (UTC), it
may not do so exactly, depending on the host environment of the Java Virtual
Machine. Nearly all modern operating systems assume that 1 day = 24 × 60 × 60 =
86400 seconds in all cases. In UTC, however, about once every year or two there is
an extra second, called a "leap second." The leap second is always added as the
last second of the day, and always on December 31 or June 30. For example, the
last minute of the year 1995 was 61 seconds long, thanks to an added leap
second. Most computer clocks are not accurate enough to be able to reflect the
leap-second distinction.
9. Calendar
The java.util.calendar class is an abstract class that provides methods for
converting between a specific instant in time and a set of calendar fields such as
YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the
calendar fields, such as getting the date of the next week.
Following are the important points about Calendar:
This class also provides additional fields and methods for implementing a
concrete calendar system outside the package.
Calendar defines the range of values returned by certain calendar fields.
10. TimeZone
A time zone is a region of the earth where the same standard time is used. Each
time zone is described by an identifier and usually has the format region/city
(Asia/Tokyo) and an offset from Greenwich/UTC time.
UTC:
Coordinated Universal Time, abbreviated as UTC, is the primary time standard by
which the world regulates clocks and time. It is within about 1 second of mean
solar time at 0° longitude, it does not observe daylight saving time.
11. Continue..
Daylight saving time (DST) or summer time is the practice of advancing clocks
during summer months by one hour so that evening daylight lasts an hour longer,
while sacrificing normal sunrise times. Typically, regions with summer time adjust
clocks forward one hour close to the start of spring and adjust them backward in
the autumn to standard time. People use the terms "spring forward" and "fall back"
when referring to this.
The Java TimeZone class is a class that represents time zones, and is helpful
when doing calendar arithmetics across time zones.
12. Continue..
Typically, you get a TimeZone using getDefault which creates a TimeZone based
on the time zone where the program is running. For example, for a program
running in Japan, getDefault creates a TimeZone object based on Japanese
Standard Time. You can also get a TimeZone using getTimeZone along with a
time zone ID. For instance, the time zone ID for the U.S. Pacific Time zone is
"America/Los_Angeles". So, you can get a U.S. Pacific Time TimeZone object with:
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
13. Locale
A Locale object represents a specific geographical, political, or cultural region. An
operation that requires a Locale to perform its task is called locale-sensitive and
uses the Locale to tailor information for the user. For example, displaying a
number is a locale-sensitive operation— the number should be formatted
according to the customs and conventions of the user's native country, region, or
culture.
14. Timer
The java.util.Timer class provides facility for threads to schedule tasks for future
execution in a background thread.
This class is thread-safe i.e multiple threads can share a single Timer object
without the need for external synchronization.
This class schedules tasks for one-time execution, or for repeated execution at
regular intervals.
All constructors start a timer thread.
16. Formatter
A formatter is an object that is responsible for encoding and serializing data into
messages on one end, and deserializing and decoding messages into data on the
other end.
The java.util.Formatter class provides support for layout justification and
alignment, common formats for numeric, string, and date/time data, and locale-
specific output
17. Continue..
Difference between the printf and format methods in Java?
printf() and format()both methods are used to format String in Java and more or
less similar. printf()is more close to C programming language because of identical
name used in C programming language, Anyone who has work in C previously can
easily start with this printf() method also its look more as a replacement of
System.out.println(). if you don't want to print just want a formatted string for any
other purpose String format() method is a way to go. In summary you can say that
printf()writes on stdout while format() return you a formatted string.