0% found this document useful (0 votes)
7 views17 pages

Core Java Samples PDF

This document discusses the history and evolution of the Java programming language, emphasizing its lineage from C and C++. It highlights key concepts such as inheritance, polymorphism, and type conversion, which are foundational to Java's design and functionality. The document also outlines the Object class and its significance in Java, as well as practical examples of Java's syntax and features.

Uploaded by

jinwooosung.07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views17 pages

Core Java Samples PDF

This document discusses the history and evolution of the Java programming language, emphasizing its lineage from C and C++. It highlights key concepts such as inheritance, polymorphism, and type conversion, which are foundational to Java's design and functionality. The document also outlines the Object class and its significance in Java, as well as practical examples of Java's syntax and features.

Uploaded by

jinwooosung.07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

CHAPTER

1
The History and
Evolution of Java
To fully understand Java, one must understand the reasons behind its creation, the forces
that shaped it, and the legacy that it inherits. Like the successful computer languages that
came before, Java is a blend of the best elements of its rich heritage combined with the
innovative concepts required by its unique mission. While the remaining chapters of
this book describe the practical aspects of Java—including its syntax, key libraries, and
applications—this chapter explains how and why Java came about, what makes it so
important, and how it has evolved over the years.
Although Java has become inseparably linked with the online environment of the Internet,
it is important to remember that Java is first and foremost a programming language.
Computer language innovation and development occur for two fundamental reasons:

• To adapt to changing environments and uses


• To implement refinements and improvements in the art of programming
As you will see, the development of Java was driven by both elements in nearly
equal measure.

Java’s Lineage
Java is related to C++, which is a direct descendant of C. Much of the character of Java is
inherited from these two languages. From C, Java derives its syntax. Many of Java’s object-
oriented features were influenced by C++. In fact, several of Java’s defining characteristics
come from—or are responses to—its predecessors. Moreover, the creation of Java was deeply
rooted in the process of refinement and adaptation that has been occurring in computer
programming languages for the past several decades. For these reasons, this section reviews
the sequence of events and forces that led to Java. As you will see, each innovation in language
design was driven by the need to solve a fundamental problem that the preceding languages
could not solve. Java is no exception.

3
24 PART I The Java Language

Figure 2-1 Encapsulation: public methods can be used to protect private data.

If you wanted to describe a more specific class of animals, such as mammals, they would have
more specific attributes, such as type of teeth and mammary glands. This is known as a
subclass of animals, where animals are referred to as mammals’ superclass.
Since mammals are simply more precisely specified animals, they inherit all of the
attributes from animals. A deeply inherited subclass inherits all of the attributes from each
of its ancestors in the class hierarchy.
Inheritance interacts with encapsulation as well. If a given class encapsulates some
attributes, then any subclass will have the same attributes plus any that it adds as part of its
specialization (see Figure 2-2). This is a key concept that lets object-oriented programs grow
in complexity linearly rather than geometrically. A new subclass inherits all of the attributes
of all of its ancestors. It does not have unpredictable interactions with the majority of the rest
of the code in the system.
Chapter 2 An Overview of Java 25

Part I
Figure 2-2 Labrador inherits the encapsulation of all its superclasses.

Polymorphism
Polymorphism (from Greek, meaning “many forms”) is a feature that allows one interface to
be used for a general class of actions. The specific action is determined by the exact nature of
the situation. Consider a stack (which is a last-in, first-out list). You might have a program
that requires three types of stacks. One stack is used for integer values, one for floating-point
values, and one for characters. The algorithm that implements each stack is the same, even
though the data being stored differs. In a non–object-oriented language, you would be
required to create three different sets of stack routines, with each set using different names.
However, because of polymorphism, in Java you can specify a general set of stack routines
that all share the same names.
Chapter 2 An Overview of Java 35

Let’s look at another example. The following program uses a block of code as the target
of a for loop.
/*

Part I
Demonstrate a block of code.

Call this file "BlockTest.java"


*/
class BlockTest {
public static void main(String[] args) {
int x, y;

y = 20;

// the target of this loop is a block


for(x = 0; x<10; x++) {
System.out.println("This is x: " + x);
System.out.println("This is y: " + y);
y = y - 2;
}
}
}

The output generated by this program is shown here:


This is x: 0 This is y: 20 This is x: 1 This
is y: 18 This is x: 2 This is y: 16 This is
x: 3 This is y: 14 This is x: 4 This is y:
12 This is x: 5 This is y: 10 This is x: 6
This is y: 8 This is x: 7 This is y: 6 This
is x: 8 This is y: 4 This is x: 9 This is y:
2

In this case, the target of the for loop is a block of code and not just a single statement.
Thus, each time the loop iterates, the three statements inside the block will be executed. This
fact is, of course, evidenced by the output generated by the program.
As you will see later in this book, blocks of code have additional properties and uses.
However, the main reason for their existence is to create logically inseparable units of code.
52 PART I The Java Language

One last point: Although blocks can be nested, you cannot declare a variable to have the
same name as one in an outer scope. For example, the following program is illegal:
// This program will not compile
class ScopeErr {

public static void main(String[] args) {


int bar = 1;
{ // creates a new scope
int bar = 2; // Compile-time error – bar already defined!
}
}
}

Type Conversion and Casting


If you have previous programming experience, then you already know that it is fairly common
to assign a value of one type to a variable of another type. If the two types are compatible,
then Java will perform the conversion automatically. For example, it is always possible to
assign an int value to a long variable. However, not all types are compatible, and thus, not
all type conversions are implicitly allowed. For instance, there is no automatic conversion
defined from double to byte. Fortunately, it is still possible to obtain a conversion between
incompatible types. To do so, you must use a cast, which performs an explicit conversion
between incompatible types. Let’s look at both automatic type conversions and casting.
Java’s Automatic Conversions
When one type of data is assigned to another type of variable, an automatic type conversion
will take place if the following two conditions are met:

• The two types are compatible.


• The destination type is larger than the source type.
When these two conditions are met, a widening conversion takes place. For example,
the int type is always large enough to hold all valid byte values, so no explicit cast statement
is required.
For widening conversions, the numeric types, including integer and floating-point types,
are compatible with each other. However, there are no automatic conversions from the
numeric types to char or boolean. Also, char and boolean are not compatible with each other.
As mentioned earlier, Java also performs an automatic type conversion when storing a
literal integer constant into variables of type byte, short, long, or char.
Casting Incompatible Types
Although the automatic type conversions are helpful, they will not fulfill all needs. For
example, what if you want to assign an int value to a byte variable? This conversion will not
be performed automatically, because a byte is smaller than an int. This kind of conversion
is sometimes called a narrowing conversion, since you are explicitly making the value narrower
so that it will fit into the target type.
196 PART I The Java Language

class SecondDerivedClass extends FirstDerivedClass {


int y;
// ...
}

class TypeInferenceAndInheritance {

// Return some type of MyClass object.


static MyClass getObj(int which) {
switch(which) {
case 0: return new MyClass();
case 1: return new FirstDerivedClass();
default: return new SecondDerivedClass();
}
}

public static void main(String[] args) {

// Even though getObj() returns different types of //


objects within the MyClass inheritance hierarchy, //
its declared return type is MyClass. As a result, //
in all three cases shown here, the type of the //
variables is inferred to be MyClass, even though //
different derived types of objects are obtained.

// Here, getObj() returns a MyClass object.


var mc = getObj(0);

// In this case, a FirstDerivedClass object is returned.


var mc2 = getObj(1);

// Here, a SecondDerivedClass object is returned.


var mc3 = getObj(2);

// Because the types of both mc2 and mc3 are inferred //


as MyClass (because the return type of getObj() is //
MyClass), neither mc2 nor mc3 can access the fields //
declared by FirstDerivedClass or SecondDerivedClass.
// mc2.x = 10; // Wrong! MyClass does not have an x field.
// mc3.y = 10; // Wrong! MyClass does not have a y field.
}
}

In the program, a hierarchy is created that consists of three classes, at the top of which is
MyClass. FirstDerivedClass is a subclass of MyClass, and SecondDerivedClass is a
subclass of FirstDerivedClass. The program then uses type inference to create three
variables, called mc, mc2, and mc3 by calling getObj( ). The getObj( ) method has a return
type of MyClass (the superclass), but returns objects of type MyClass, FirstDerivedClass,
or SecondDerivedClass, depending on the argument that it is passed. As the output shows,
the inferred type is determined by the return type of getObj( ), not by the actual type of the
object obtained. Thus, all three variables will be of type MyClass.
Chapter 8 Inheritance 197

The Object Class


There is one special class, Object, defined by Java. All other classes are subclasses of Object.

Part I
That is, Object is a superclass of all other classes. This means that a reference variable of
type Object can refer to an object of any other class. Also, since arrays are implemented as
classes, a variable of type Object can also refer to any array.
Object defines the following methods, which means that they are available in every object.

Method Purpose
Creates a new object that is the same as the object being
Object clone( ) cloned.
boolean equals(Object object) Determines whether one object is equal to another.
void finalize( ) Called before an unused object is recycled. (Deprecated
by JDK 9.)
Obtains the class of an object at run time.
Class<?> getClass( )
Returns the hash code associated with the invoking
int hashCode( )
object.
Resumes execution of a thread waiting on the invoking
void notify( )
object.
Resumes execution of all threads waiting on the invoking
void notifyAll( )
object.
Returns a string that describes the object.
String toString( )
Waits on another thread of execution.
void wait( )
void wait(long milliseconds)
void wait(long milliseconds,
int nanoseconds)

The methods getClass( ), notify( ), notifyAll( ), and wait( ) are declared as final. You may
override the others. These methods are described elsewhere in this book. However, notice
two methods now: equals( ) and toString( ). The equals( ) method compares two objects. It
returns true if the objects are equal, and false otherwise. The precise definition of equality
can vary, depending on the type of objects being compared. The toString( ) method returns a
string that contains a description of the object on which it is called. Also, this method is
automatically called when an object is output using println( ). Many classes override this
method. Doing so allows them to tailor a description specifically for the types of objects that
they create.
One last point: Notice the unusual syntax in the return type for getClass( ). This relates
to Java’s generics feature, which is described in Chapter 14.
Chapter 11 Multithreaded Programming 275

Part I
Figure 11-1 Thread states

Figure 11-1 diagrams how the various thread states relate.


Given a Thread instance, you can use getState( ) to obtain the state of a thread. For
example, the following sequence determines if a thread called thrd is in the RUNNABLE
state at the time getState( ) is called:
Thread.State ts = thrd.getState();

if(ts == Thread.State.RUNNABLE) // ...

It is important to understand that a thread’s state may change after the call to getState( ).
Thus, depending on the circumstances, the state obtained by calling getState( ) may not
reflect the actual state of the thread only a moment later. For this (and other) reasons,
getState( ) is not intended to provide a means of synchronizing threads. It’s primarily used
for debugging or for profiling a thread’s run-time characteristics.

Using a Factory Method to Create and Start a Thread


In some cases, it is not necessary to separate the creation of a thread from the start of its
execution. In other words, sometimes it is convenient to create and start a thread at the same
time. One way to do this is to use a static factory method. A factory method is a method that
returns an object of a class. Typically, factory methods are static methods of a class. They are
Chapter 14 Generics 381

// Pass the constructor a reference to


// an object of type T.
Gen(T o) {

Part I
ob = o;
}

// Return ob.
T getOb() {
System.out.print("Gen's getOb(): " );
return ob;
}
}

// A subclass of Gen that overrides getOb().


class Gen2<T> extends Gen<T> {

Gen2(T o) {
super(o);
}

// Override getOb().
T getOb() {
System.out.print("Gen2's getOb(): ");
return ob;
}
}

// Demonstrate generic method override.


class OverrideDemo {
public static void main(String[] args) {

// Create a Gen object for Integers.


Gen<Integer> iOb = new Gen<Integer>(88);

// Create a Gen2 object for Integers.


Gen2<Integer> iOb2 = new Gen2<Integer>(99);

// Create a Gen2 object for Strings.


Gen2<String> strOb2 = new Gen2<String> ("Generics Test");

System.out.println(iOb.getOb());
System.out.println(iOb2.getOb());
System.out.println(strOb2.getOb());
}
}

The output is shown here:


Gen's getOb(): 88
Gen2's getOb(): 99
Gen2's getOb(): Generics Test

As the output confirms, the overridden version of getOb( ) is called for objects of type Gen2,
but the superclass version is called for objects of type Gen.
498 PART II The Java Library

trim( ) and strip( )


The trim( ) method returns a copy of the invoking string from which any leading and trailing
spaces have been removed. As it relates to this method, spaces consist of those characters with
a value of 32 or less. The trim( ) method has this general form:
String trim( )
Here is an example:
String s = " Hello World ".trim();

This puts the string "Hello World" into s.


The trim( ) method is quite useful when you process user commands. For example,
the following program prompts the user for the name of a state and then displays that state’s
capital. It uses trim( ) to remove any leading or trailing spaces that may have inadvertently
been entered by the user.
// Using trim() to process commands.
import java.io.*;

class UseTrim {
public static void main(String[] args)
throws IOException
{
// create a BufferedReader using System.in
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in, System.console().charset()));
String str;

System.out.println("Enter 'stop' to quit.");


System.out.println("Enter State: ");
do {
str = br.readLine();
str = str.trim(); // remove whitespace

if(str.equals("Illinois"))
System.out.println("Capital is Springfield.");
else if(str.equals("Missouri"))
System.out.println("Capital is Jefferson City.");
else if(str.equals("California"))
System.out.println("Capital is Sacramento.");
else if(str.equals("Washington"))
System.out.println("Capital is Olympia.");
// ...
} while(!str.equals("stop"));
}
}

Beginning with JDK 11, Java also provides the methods strip( ), stripLeading( ), and
stripTrailing( ). The strip( ) method removes all whitespace characters (as defined by Java)
from the beginning and end of the invoking string and returns the result. Such whitespace
characters include, among others, spaces, tabs, carriage returns, and line feeds.
Chapter 18 String Handling 501

The output is shown here:


Alpha Beta Gamma
John, ID#: 569, E-mail: [email protected]

In the first call to join( ), a space is inserted between each string. In the second call, the
delimiter is a comma followed by a space. This illustrates that the delimiter need not be just a
single character.
The second form of join( ) lets you join a list of strings obtained from an object that
implements the Iterable interface. Iterable is implemented by the Collections Framework
classes described in Chapter 20, among others. See Chapter 19 for information on Iterable.

Part II
Additional String Methods
In addition to those methods discussed earlier, String has many other methods. Several are
summarized in the following table:

Method Description
int codePointAt(int i) Returns the Unicode code point at the location specified by i.
int codePointBefore(int i) Returns the Unicode code point at the location that
precedes that specified by i.
int codePointCount(int start, int end) Returns the number of code points in the portion of the
invoking String that are between start and end–1.
boolean contains(CharSequence str) Returns true if the invoking object contains the string
specified by str. Returns false otherwise.
boolean contentEquals(CharSequence str) Returns true if the invoking string contains the same
string as str. Otherwise, returns false.
boolean contentEquals(StringBuffer str) Returns true if the invoking string contains the same
string as str. Otherwise, returns false.
static String format(String fmtstr, Returns a string formatted as specified by fmtstr.
Object ... args)
(See Chapter 20 for details on formatting.)
static String format(Locale loc,
Returns a string formatted as specified by fmtstr.
String fmtstr,
Object ... args) Formatting is governed by the locale specified by loc.
(See Chapter 20 for details on formatting.)
String formatted(Object .... args)
Returns a string formatted as specified by the invoking string
applied to args. (See Chapter 21 for details on formatting.)
String indent(int num)
When num is positive, indents each line in the invoking string
by num spaces. When num is negative, each line has num
leading white space characters deleted, if possible.
Otherwise,
when
the num is negative, leading white space is deleted until
first non-white space character is encountered. In all cases,
boolean isEmpty( ) including when num is zero, each line will end with a newline
character. Returns the resulting string.
Returns true if the invoking string contains no characters
and has a length of zero.
Chapter 19 Exploring java.lang 549

Trigonometric Functions
The following methods accept a double parameter for an angle in radians and return the
result of their respective trigonometric function:

Method Description
static double sin(double arg) Returns the sine of the angle specified by arg in radians.
static double cos(double arg) Returns the cosine of the angle specified by arg in radians.
static double tan(double arg) Returns the tangent of the angle specified by arg in radians.

Part II
The next methods take as a parameter the result of a trigonometric function and return,
in radians, the angle that would produce that result. They are the inverse of their non-arc
companions.

Method Description
static double asin(double arg) Returns the angle whose sine is specified by arg.
static double acos(double arg) Returns the angle whose cosine is specified by arg.
static double atan(double arg) Returns the angle whose tangent is specified by
static double atan2(double x, double y) arg. Returns the angle whose tangent is x/y.

The next methods compute the hyperbolic sine, cosine, and tangent of an angle:

Method Description
static double sinh(double arg) Returns the hyperbolic sine of the angle specified by arg.
static double cosh(double arg) Returns the hyperbolic cosine of the angle specified by arg.
static double tanh(double arg) Returns the hyperbolic tangent of the angle specified by arg.

Exponential Functions
Math defines the following exponential methods:

Method Description
static double cbrt(double arg) static Returns the cube root of arg. Returns e to the
double exp(double arg) static double arg. Returns e to the arg–1. Returns the natural
expm1(double arg) static double logarithm of arg. Returns the base 10 logarithm
log(double arg) static double for arg. Returns the natural logarithm for arg + 1.
log10(double arg) static double Returns y raised to the x; for example, pow(2.0,
log1p(double arg) static double 3.0) returns 8.0.
pow(double y, double x) Returns arg × 2factor.
Returns arg × 2factor.
static double scalb(double arg, int factor)
Returns the square root of arg.
static float scalb(float arg, int factor)
static double sqrt(double arg)
Chapter 21 java.util Part 2: More Utility Classes 691

The output is the same as before.


The Java printf( ) Connection
Although there is nothing technically wrong with using Formatter directly (as the preceding
examples have done) when creating output that will be displayed on the console, there is a
more convenient alternative: the printf( ) method. The printf( ) method automatically uses
Formatter to create a formatted string. It then displays that string on System.out, which is
the console by default. The printf( ) method is defined by both PrintStream and
PrintWriter. The printf( ) method is described in Chapter 22.

Part II
Scanner
Scanner is the complement of Formatter. It reads formatted input and converts it into its
binary form. Scanner can be used to read input from the console, a file, a string, or any
source that implements the Readable interface or ReadableByteChannel. For example, you
can use Scanner to read a number from the keyboard and assign its value to a variable. As
you will see, given its power, Scanner is surprisingly easy to use.
The Scanner Constructors
Scanner defines many constructors. A sampling is shown in Table 21-14. In general, a
Scanner can be created for a String, an InputStream, a File, a Path, or any object that
implements the Readable or ReadableByteChannel interfaces. Here are some examples.
The following sequence creates a Scanner that reads the file Test.txt:
FileReader fin = new FileReader("Test.txt");
Scanner src = new Scanner(fin);

This works because FileReader implements the Readable interface. Thus, the call to the
constructor resolves to Scanner(Readable).
This next line creates a Scanner that reads from standard input, which is the keyboard
by default:
Scanner conin = new Scanner(System.in);

This works because System.in is an object of type InputStream. Thus, the call to the
constructor maps to Scanner(InputStream).
The next sequence creates a Scanner that reads from a string.
String instr = "10 99.88 scanning is easy.";
Scanner conin = new Scanner(instr);

Scanning Basics
Once you have created a Scanner, it is a simple matter to use it to read formatted input.
In general, a Scanner reads tokens from the underlying source that you specified when the
Scanner was created. As it relates to Scanner, a token is a portion of input that is delineated
by a set of delimiters, which is whitespace by default. A token is read by matching it with a
particular regular expression, which defines the format of the data. Although Scanner allows
708 PART II The Java Library

Inter face Abstract Method


BiConsumer<T, U> void accept(T tVal, U uVal)
Description: Acts on tVal and uVal.
BiFunction<T, U, R> R apply(T tVal, U uVal)
Description: Acts on tVal and uVal and returns the result.
BinaryOperator<T> T apply(T val1, T val2)
Description: Acts on two objects of the same type and returns
the result, which is also of the same type.

BiPredicate<T, U> boolean test(T tVal, U uVal)


Description: Returns true if tVal and uVal satisfy the condition
defined by test( ) and false otherwise.
boolean getAsBoolean( )
B o ole anSupplier
Description: Returns a boolean value.
void accept(T val)
Consumer<T>
Description: Acts on val.
double applyAsDouble(double val1, double val2)
DoubleBinaryOperator
Description: Acts on two double values and returns a double
re sult .
void accept(double val)
D oubleConsumer
Description: Acts on val.
R apply(double val)
DoubleFunction<R> Description: Acts on a double value and returns the result.
boolean test(double val)
D oublePre dic ate Description: Returns true if val satisfies the condition defined
by test( ) and false otherwise.
double getAsDouble( )
D oubleSupplier Description: Returns a double result.
int applyAsInt(double val)
DoubleToIntFunction Description: Acts on a double value and returns the result as an
int.
long applyAsLong(double val)
DoubleToLongFunction Description: Acts on a double value and returns the result as a
long.
double applyAsDouble(double val)
DoubleUnaryOperator Description: Acts on a double and returns a double result.
R apply(T val)
Function<T, R> Description: Acts on val and returns the result.
int applyAsInt(int val1, int val2)
IntBinaryOperator Description: Acts on two int values and returns an int result.

Table 21-18 Functional Interfaces Defined by java.util.function and Their Abstract Methods (continued)
834 PART II The Java Library

The AdjustmentListener Interface


This interface defines the adjustmentValueChanged( ) method that is invoked when an
adjustment event occurs. Its general form is shown here:
void adjustmentValueChanged(AdjustmentEvent ae)

The ComponentListener Interface


This interface defines four methods that are invoked when a component is resized, moved,
shown, or hidden. Their general forms are shown here:
void componentResized(ComponentEvent ce)
void componentMoved(ComponentEvent ce)
void componentShown(ComponentEvent ce)
void componentHidden(ComponentEvent ce)

The ContainerListener Interface


This interface contains two methods. When a component is added to a container,
componentAdded( ) is invoked. When a component is removed from a container,
componentRemoved( ) is invoked. Their general forms are shown here:
void componentAdded(ContainerEvent ce)
void componentRemoved(ContainerEvent ce)

The FocusListener Interface


This interface defines two methods. When a component obtains keyboard focus,
focusGained( ) is invoked. When a component loses keyboard focus, focusLost( )
is called. Their general forms are shown here:
void focusGained(FocusEvent fe)
void focusLost(FocusEvent fe)

The ItemListener Interface


This interface defines the itemStateChanged( ) method that is invoked when the state of an
item changes. Its general form is shown here:
void itemStateChanged(ItemEvent ie)

The KeyListener Interface


This interface defines three methods. The keyPressed( ) and keyReleased( ) methods are
invoked when a key is pressed and released, respectively. The keyTyped( ) method is invoked
when a character has been entered.
For example, if a user presses and releases the a key, three events are generated in
sequence: key pressed, typed, and released. If a user presses and releases the home key,
two key events are generated in sequence: key pressed and released.
852 PART II The Java Library

techniques needed to use the AWT. From there, you will be able to explore other parts of the
AWT on your own. You will also be ready to move on to Swing.

NOTE If you have not yet read Chapter 25, please do so now. It provides an overview of event handling, which
is used by many of the examples in this chapter.

AWT Classes
The AWT classes are contained in the java.awt package. It is one of Java’s largest packages.
Fortunately, because it is logically organized in a top-down, hierarchical fashion, it is easier to
understand and use than you might at first believe. Beginning with JDK 9, java.awt is part of the
java.desktop module. Table 26-1 lists some of the many AWT classes.
Although the basic structure of the AWT has been the same since Java 1.0, some of the
original methods were deprecated and replaced by new ones. For backward-compatibility,
Java still supports all the original 1.0 methods. However, because these methods are not for
use with new code, this book does not describe them.

Class Description
AWTEvent Encapsulates AWT events. Dispatches events to multiple listeners. The
AWTEventMulticaster border layout manager. Border layouts use five components: North,
B orderL ayout South, East, West, and Center.
Creates a push button control.
Button A blank, semantics-free window.
Canvas The card layout manager. Card layouts emulate index cards. Only the one
C ardL ayout on top is showing.
Creates a check box control.
Checkbox Creates a group of check box controls.
CheckboxGroup Creates an on/off menu item.
C he ckb oxMenuItem Creates a pop-up list.
Choice Manages colors in a portable, platform-independent fashion.
Color An abstract superclass for various AWT components.
Component A subclass of Component that can hold other components.
Container Encapsulates a bitmapped cursor.
Cursor Creates a dialog window.
Dialog Specifies the dimensions of an object. The width is stored in width, and
the height is stored in height. Queues events. Creates a window from which
Dimension
a file can be selected.

EventQueue
FileDialog

Table 26-1 A Sampling of AWT Classes (continued)

You might also like