Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

Chapter 18: java.util Part 2: More Utility Classes 507


// OR bits
bits2.or(bits1);
System.out.println("\nbits2 OR bits1: ");
System.out.println(bits2);

// XOR bits
bits2.xor(bits1);
System.out.println("\nbits2 XOR bits1: ");
System.out.println(bits2);
}
}

The output from this program is shown here. WhentoString( )converts aBitSetobject to its
string equivalent, each set bit is represented by its bit position. Cleared bits are not shown.

Initial pattern in bits1:
{0, 2, 4, 6, 8, 10, 12, 14}

Initial pattern in bits2:
{1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14}

bits2 AND bits1:
{2, 4, 6, 8, 12, 14}

bits2 OR bits1:
{0, 2, 4, 6, 8, 10, 12, 14}

bits2 XOR bits1:
{}

Date


TheDateclass encapsulates the current date and time. Before beginning our examination of
Date, it is important to point out that it has changed substantially from its original version
defined by Java 1.0. When Java 1.1 was released, many of the functions carried out by the
originalDateclass were moved into theCalendarandDateFormatclasses, and as a result,
many of the original 1.0Datemethods were deprecated. Since the deprecated 1.0 methods
should not be used for new code, they are not described here.
Datesupports the following constructors:

Date( )
Date(longmillisec)

The first constructor initializes the object with the current date and time. The second constructor
accepts one argument that equals the number of milliseconds that have elapsed since midnight,
January 1, 1970. The nondeprecated methods defined byDateare shown in Table 18-3.Datealso
implements theComparableinterface.
Free download pdf