Java 2 考试指南(含盘,英文原版)
分類: 图书,计算机/网络,程序设计,Java Java Script J2EE,
作者: 美 斯坦尼克 著
出 版 社: 电子工业出版社
出版时间: 2002-4-1字数: 924000版次: 1页数: 568印刷时间: 2002/04/01开本:印次:纸张: 胶版纸I S B N : 9787505374287包装: 平装内容简介
本书是美国McGraw-Hill公司出版的畅销谁系列丛书All-in-Oin中的一本。书中包括参加 Java 2 程序员和开发人员认证考试的全部内容,主要涉及答题技巧、 Java 编程基础和关键字、应用对象和类、访问和管理数据库、设计应用程序接口等多方面内容。各章包含有最新示例、练习及问答。本书所附光盘提供了最接近真实测试环境的大量原汗原味的考试师和自测题。对有意参加 Java 2 认证考试及学习 Java 2 的读者而言,本书是一本优秀的参考用书。
目录
Introduction1
Part I Studying for the Programmer誷 Exam7
Chapter 1 Programmer Exam Roadmap8
What Is the Programmer Exam Like?8
What誷 on the Exam8
Declarations and Access Control9
Flow Control and Exception Handling9
Garbage Collection9
Language Fundamentals9
Operators and Assignments9
Overloading, Overriding Runtime Type, and Object Orientation10
Threads10
The java.awt Package ?Layout10
The java.lang Package10
The java.util Package10
The java.io Package11
How Does the Text Map to the Programmer Exam Objectives?11
How the Test Is Administered11
How to Sign up for and Take the Exams11
Test-Taking Tips for the Programmer Exam12
What the Test Program Looks Like for the Programmer Exam12
Be Careful!13
Take Your Time and Answer the Easy Ones First13
Beware of Tricks14
Understand Why the Question Is on the Test14
Know Your Test Center15
What Happens When You誶e Done?16
Sun誷 Take on Certification16
How Sun Manages the Certification Process16
Where Certification Is Heading17
Chapter 2 Java Programming Fundamentals18
Java Programming Concepts18
Objects18
Classes19
Packages19
Inheritance19
Encapsulation20
Access Controls20
Java誷 Characteristics21
Design for Distributed Networks22
Design for Multithreading22
Design for Ease of Use and Reuse22
Design for Security23
Working with Java Applets and Applications23
The Java Specification and the API23
Java 1.124
Java 2: JDK 1.224
Java 2: JDK 1.325
Review Questions25
Answers to Review Questions26
Chapter 3 Java Keywords27
An Alphabetical List of All the Keywords27
Organizing Classes27
Defining Classes28
Keywords for Classes and Members28
Simple Data Types30
Values and Variables30
Exception Handling31
Instance Creation and Testing32
Control Flow32
Exercises34
Exercise 3-134
Exercise 3-234
Exercise 3-334
Answers to the Exercises34
Review Questions35
Answers to Review Questions36
Chapter 4 Java Building Blocks37
Identifiers37
Literals38
Boolean Literals38
Character Literals38
Exercise 4-139
String Literals39
Exercise 4-240
Integer Literals40
Floating-Point Literals41
Separators41
Operators41
Exercise 4-342
Exercise 4-443
Comments43
Answers to the Exercises44
Review Questions44
Answers to Review Questions46
Chapter 5 Memory and Garbage Collection47
Garbage Collection47
When Does an Object Become Eligible for Garbage Collection?48
Invoking the Garbage Collector48
Finalization49
Exercise 5-149
Exercise 5-249
Accessing Members50
Exercise 5-351
Passing Parameters to a Method51
Exercise 5-454
Forcing Garbage Collection55
Answers to the Exercises55
Review Questions57
Answers to Review Questions59
Chapter 6 Data Types and Values60
Data Types60
Variables and Data Types61
Primitive Data Types61
Integer Data Types62
Character Values63
Floating-Point Arithmetic64
Booleans65
Casting65
Exercises66
Exercise 6.166
Exercise 6.266
Exercise 6.366
Arrays66
Declaring and Initializing Arrays67
One-Dimensional Arrays67
Initializing an Array When it is Allocated68
Exercise 6.469
Arrays of Arrays69
Where Arrays Fit into the Class Hierarchy70
Answers to the Exercises71
Review Questions72
Answers to Review Questions73
Chapter 7 Operators74
Operators and Expressions74
Arithmetic Operators75
Assignment Operators77
Comparison Operators78
Logical Operators79
Bitwise Operators80
TheOperator81
TheOperator82
The
The &, |, and ^ Operators84
Exercises85
Exercise 7.185
Testing for an Object誷 Class Type85
Exercise 7.286
equals() and ==86
Exercise 7.387
Exercise 7.487
Operator Precedence and Evaluation Order87
Using Arrays in Expressions89
Using chars in Expressions89
Answers to the Exercises89
Review Questions92
Answers to Review Questions94
Chapter 8 Control Flow96
Using if and if . . . else Statements96
if Statements96
if . . . else Statements97
Nested if Statements97
Legal Values for if Statements98
Exercise 8.198
Looping Expressions99
while Statements99
do-while Statements100
Legal Values for while and do-while Statements101
Iteration with for loops101
for Statements101
Controlling for Loops with Expressions102
Nested for Loops102
Switch and Case Statements103
switch case103
Nested switch case104
Using Jump Statements105
break105
continue105
Labeled Loops106
Exercise 8.2108
Using && and ||109
Exercise 8.3109
Answers to the Exercises109
Review Questions110
Answers to Review Questions111
Chapter 9 Methods112
Defining Methods112
Methods Definitions112
Return Types113
Method Modifiers114
Exercise 9.1116
Overloading a Method117
Exercise 9.2118
Overriding a Method118
Access Control to Subclasses119
Inheriting Synchronized and Abstract119
Return Types119
Parameter Types120
Exceptions120
Exercise 9.3120
Object References to Base and Derived Classes121
Answers to the Exercises122
Review Questions124
Answers to Review Questions125
Chapter 10 Constructors126
Constructor Essentials126
The Default Constructor127
Defining, Overloading, and Overriding a Constructor128
Invoking Another Constructor130
Instance Variables in Constructors130
Exercise 10.1132
Exercise 10.2132
Exercise 10.3133
Answers to the Exercises133
Review Questions134
Answers to Review Questions136
Chapter 11 Objects and Classes137
Objects137
Creating and Destroying Objects138
Classes139
Declaring a Class139
Application Class Structures140
Applet Class Structures140
Class Variables143
Instance Variables144
Static Variables145
Predefined Instances145
null145
this145
super146
Object-Oriented Relationships Using 詉s a?and 詇as a?146
Exercises148
Exercise 11.1148
Exercise 11.2148
Class Keywords148
public149
abstract149
strictfp150
final150
Exercise 11.3151
Exercise 11.4151
Variable Keywords151
static151
final151
transient152
volatile152
Exercise 11.5152
Access Control Keywords152
public152
private153
protected153
Exercise 11.6153
Exercise 11.7154
Exercise 11.8154
Exercise 11.9154
Exercise 11.10154
Casting Classes155
Inner Classes156
Creating Inner Classes156
Anonymous Classes160
Static Inner Classes161
Exercise 11.11161
Answers to the Exercises162
Review Questions168
Answers to Review Questions171
Chapter 12 Packages, Inheritance, and Interfaces172
Packages172
Declaring a Package172
The CLASSPATH Environmental Variable174
Import Statements174
Package Naming Conventions175
Using Packages176
Exercise 12.1177
Exercise 12.2177
Exercise 12.3177
Exercise 12.4178
Creating a Package178
Ordering of a Java Source File180
Exercise 12.5180
Exercise 12.6181
Inheritance182
Declaring Inheritance183
Using Inheritance184
Interfaces185
Using Interfaces185
Defining Interfaces186
Using the Cloneable Interface187
Exercise 12.7188
Answers to the Exercises188
Review Questions190
Answers to Review Questions191
Chapter 13 Passing Arguments to Programs192
The main() Method192
Command Line Arguments193
Exercise 13.1194
When main() Ends195
Embedding an Applet in an HTML Page195
Passing Parameters to an Applet196
Retrieving Parameters197
Exercise 13.2198
Customizing an Applet198
Answers to the Exercises201
Review Questions203
Answers to Review Questions204
Chapter 14 Exceptions205
Exception Basics205
Working with Exceptions206
Uncaught Exceptions207
Checked and Unchecked Exceptions207
Using try, catch, and finally208
Exercise 14.1209
Common Java Exceptions210
Using Methods Defined by Exception and Throwable211
Rethrowing an Exception211
Exercise 14.2212
Which Exceptions a Method Can Throw213
Exceptions in an Overriding Method in a Subclass213
Exercise 14.3214
Creating and Throwing an Exception214
Exercise 14.4215
Answers to the Exercises215
Review Questions218
Answers to Review Questions223
Chapter 15 Multithreading224
An Overview of Threads224
Thread States224
Thread Life Cycles225
Thread Scheduling and Priorities226
Creating Threads With java.lang.Thread and java.lang.Runnable227
Subclassing Thread227
Implementing Runnable229
Exercise 15.1230
Monitors and Synchronization232
Understanding Synchronization232
Exercise 15.2234
Using wait(), notify(), and notifyAll()234
Exercise 15.3238
Managing Threads With Wait-Notify and Sleep238
Why a Thread Might Not Execute241
Exercise 15.4242
Other Useful Thread Methods242
Answers to the Exercises242
Review Questions247
Answers to Review Questions248
Chapter 16 Essential java.lang and java.util249
Wrapper Classes249
The Boolean Class249
The Character Class250
The Byte, Short, Integer, and Long Classes250
The Float and Double Classes251
Using Wrapper Classes251
Exercise 16.1252
Working with the Math Class252
abs()252
ceil()253
floor()253
max()254
min()254
random()254
round()254
sqrt()255
sin()255
cos()255
tan()255
Exercise 16.2255
The String and StringBuffer Classes255
String Operators255
The Immutability of Strings256
Methods of the String Class257
Exercise 16.3258
String Buffers258
Exercise 16.4259
Collections260
Overview of the Collections API260
Collection API Essentials262
Answers to the Exercises263
Review Questions264
Answers to Review Questions267
Chapter 17 java.io268
The java.io Package268
InputStream and OutputStream269
FilterInputStream and FilterOutputStream269
DataInput and DataOutput271
Reader and Writer272
Working with Files273
Testing to See if a File Exists273
Finding Information about a File Node274
Deleting and Renaming Files274
Creating Directories274
Navigating the File System274
Creating Files274
Exercise 17.1275
Creating Temporary Files275
Streams276
Sequencing Stream Filters276
Exercise 17.2278
Reading and Writing Data Streams278
Encoded Text Streams279
Writing To and Reading From Files281
Exercise 17.3282
Random Access Files282
File Descriptors284
Exercise 17.4285
Using Buffered Readers to Read Text Input285
Using Print Writers to Write Text Output286
Answers to the Exercises288
Review Questions290
Answers to Review Questions291
Chapter 18 java.awt: Graphics and Components293
The Abstract Windowing Toolkit (AWT)293
AWT Essentials295
Applets and AWT296
The paint() Method297
Repainting297
paint() and the Graphics Class298
Smoother Graphics298
Drawing Using a Graphics Object299
drawString()300
drawLine()300
drawRect(), fillRect()301
drawPolygon(), fillPolygon()302
drawArc(), fillArc()302
drawImage()304
Exercise 18.1304
The Image Class304
Creating a Blank Image304
Loading or Transferring an Image305
Using an ImageObserver306
Exercise 18.2308
Working with Frame Windows308
Constructing the Frame308
Sizing the Frame308
Setting the Frame Title309
Closing the Frame Window309
Creating a Frame Window in An Application310
Creating a Frame Window in An Applet311
How Java Arranges Components Within Containers313
The Component Class, Subclasses, and Methods313
TextArea313
TextField315
List315
Exercise 18.3316
Key Component Methods317
Answers to the Exercises319
Review Questions321
Answers to Review Questions322
Chapter 19 java.awt: Layout323
Components and Layout Managers323
Layout Manager Essentials323
Using Layout Managers324
FlowLayout324
BorderLayout326
GridLayout330
Other Types of Layout Managers332
Default Layout Managers332
Exercise 19.1332
Answers to the Exercises333
Review Questions334
Answers to Review Questions335
Chapter 20 java.awt: Event Handling336
Event Classes336
Listening for Events337
The Listener Interfaces339
ActionListener339
Interface Method339
AdjustmentListener340
ComponentListener340
ContainerListener340
FocusListener341
ItemListener341
KeyListener341
MouseListener341
MouseMotionListener342
TextListener342
WindowListener342
Implementing a Listener Interface343
Exercise 20.1344
Semantic and Low-Level Events344
ActionEvent344
AdjustmentEvent344
ItemEvent345
AWTEvent Subclasses345
AWTEvent345
ActionEvent345
AdjustmentEvent346
ComponentEvent346
ContainerEvent346
FocusEvent346
InputEvent346
ItemEvent346
KeyEvent346
MouseEvent347
PaintEvent347
TextEvent347
WindowEvent347
Exercise 20.2347
Extending Adapter Classes347
Exercise 20.3348
Answers to the Exercises348
Review Questions351
Answers to Review Questions352
Chapter 21 Sun Certified Programmer Practice Exam 1353
Practice Exam Number 1353
Questions353
Answers to Exam Questions374
Chapter 22 Sun Certified Programmer Practice Exam 2377
Practice Exam Number 2377
Questions377
Answers to Exam Questions393
Chapter 23 Sun Certified Programmer Practice Exam 3396
Practice Exam Number 3396
Questions396
Answers to Exam Questions416
Part II Studying for The Developer誷 Exam419
Chapter 24 Developer Exam Roadmap420
A Quick Overview420
Concepts You Should Know Before Getting Started421
The Programming Assignment421
The Essay Exam423
How to Sign Up For and Take the Exams424
How to Acquire the Programming424
Strategies for Approaching the Developer Assignment425
Chapter 25 Developing with Java426
Styles and Conventions427
Identifiers427
Comments427
Error Handling427
Java誷 Documentation Problem428
javadoc429
Helping javadoc429
javadoc Tags432
Variables432
Classes434
Methods434
Rules for Using javadoc Comments and Tags435
Examples of javadoc Comments and Tags435
Abstract Classes438
Interfaces438
Grouping Behavior438
Enforcing Your API438
Identifying Intent439
Exercise 25.1439
Packages439
Creating Packages439
Restricting Access440
Defining Subsystems440
Exercise 25.2441
Defining Access Methods441
Exercise 25.3443
Answers to the Exercises444
Review Questions446
Answers to Review Questions447
Chapter 26 Accessing and Managing Databases448
Roll-Your-Own Databases449
Accessing Databases from Multiple Clients451
Two-Tiered and Three-Tiered Architectures452
Using Java APIs453
Remote Method Invocation453
Defining a Remote Interface454
Defining a Remote Class454
Defining the Class, Interface, and Constructor455
Installing the Security Manager and Registering the Bootstrap Naming Service458
Invoking Remote Objects459
Stubs and Skeletons461
Getting Things Going461
Exercise 26.1462
JDBC462
The Need for Drivers462
Using ODBC463
Opening a Connection to a Database464
Interacting with a Database464
An Example of Using ODBC with Microsoft Access465
Exercise 26.2466
Answers to the Exercises467
Review Questions468
Answers to Review Questions469
Chapter 27 Network Programming and Communication470
A TCP/IP Primer470
Ports and Sockets472
Streams473
Designing Servers and Clients473
Handling Multiple Clients474
Client Issues475
The Networking Package476
InetAddress476
Socket and ServerSocket476
Internet Streams478
Client-Server Examples479
Writing a Single-Client Server in Java479
server()487
client()488
action()488
run() for SingleChatReceive488
Cleaning Up489
Writing a Multi-Client Server in Java489
server()494
run()494
broadcast()495
cleanUp()495
The Client495
Cleaning Up499
Exercise 27.1499
Exercise 27.2500
Uniform Resource Locator500
Answers to the Exercises501
Review Questions511
Answers to Review Questions512
Chapter 28 Designing Application Interfaces513
Mix and Match!513
Using One Layout Manager514
Exercise 28.1520
Changing Your Look520
Text520
Font and Color521
Replacing a Component521
Exercise 28.2521
Working with Frames522
Closing the Frame522
Making an Applet a Standalone Application523
Exercise 28.3523
Answers to the Exercises523
Review Questions527
Answers to Review Questions528
Chapter 29 Sun Certified Developer Practice Programming Assignment529
The Scenario529
The Prototype Specifications530
The Design Completed So Far530
The New Design532
The Code Completed So Far533
What You Will Add to the Code537
The Database538
The Server538
The Client538
The User Interface538
The Protocol538
Making a New Reservation539
Delete a Passenger誷 Reservation539
Finding a Passenger誷 Seat539
Finding All Open Seats539
Retrieving the List of Passengers539
What the User Interface Should Look Like when You誶e Done539
Updating the Passenger List541
Final Words of Advice541
One Possible Answer for the Client Side542
Client.java542
TopFrame.java545
EdnaUI.java545
NewPassenger.java548
DeletePassenger.java549
One Possible Answer for the Server Side551
Server.java (Including ClientServerThread)551
The Three Missing Methods from DB.java558
Chapter 30 Sun Certified Developer Practice Essay Exam560
Questions560
Answers561
Part III Appendices563
Appendix A What誷 on the CD-ROM564
How the CD is Organized564
Source Code564
Sun誷 JDK564
Where to Find More564
What Is the Test Engine?565
Appendix B The JDK566
The Pieces of the JDK566
The Compiler566
The Runtime Environment for Stand-Alone Programs567
The Documentation Tool567
The Applet Viewer568