4276FM.fm Page ix Thursday, October 2, 2003 11:22 AM at a Glance Introduction Assessment Test xix xxv Part I The Programmer s Exam 1 Chapter 1 Language Fundamentals 3 Chapter 2 Operators and Assignments 29 Chapter 3 Modifiers 71 Chapter 4 Converting and Casting 97 Chapter 5 Flow Control, Assertions, and Exception Handling 123 Chapter 6 Objects and Classes 159 Chapter 7 Threads 193 Chapter 8 The java.lang and java.util Packages 227 Part II The Developer s Exam 261 Chapter 9 Taking the Developer s Exam 263 Chapter 10 Creating the User Interface with Swing 295 Chapter 11 Layout Managers 337 Chapter 12 Writing the Network Protocol 379 Chapter 13 Connecting Client and Server 415 Chapter 14 Enhancing and Extending the Database 439 Chapter 15 Building the Database Server 465 Appendix A Practice Exam 485 COPYRIGHTED MATERIAL Glossary 505 Index 519
4276FM.fm Page x Thursday, October 2, 2003 11:22 AM Introduction Assessment Test xix xxv Part I The Programmer s Exam 1 Chapter 1 Language Fundamentals 3 Source Files 4 Keywords and Identifiers 5 Primitive Data Types 6 Literals 9 boolean Literals 9 char Literals 9 Integral Literals 10 Floating-Point Literals 10 String Literals 10 Arrays 11 Class Fundamentals 13 The main() Method 14 Variables and Initialization 14 Argument Passing: By Reference or By Value 16 Garbage Collection 19 Summary 21 Exam Essentials 22 Key Terms 23 Review Questions 24 Answers to Review Questions 27 Chapter 2 Operators and Assignments 29 Evaluation Order 31 The Unary Operators 31 The Increment and Decrement Operators: ++ and -- 32 The Unary Plus and Minus Operators: + and - 32 The Bitwise Inversion Operator: ~ 33 The Boolean Complement Operator:! 33 The Cast Operator: (type) 34 The Arithmetic Operators 35 The Multiplication and Division Operators: * and / 35 The Modulo Operator: % 36 The Addition and Subtraction Operators: + and - 37 Arithmetic Error Conditions 40
4276FM.fm Page xi Thursday, October 2, 2003 11:22 AM xi The Shift Operators: <<, >>, and >>> 41 Fundamentals of Shifting 41 Shifting Negative Numbers 42 Reduction of the Right Operand 45 Arithmetic Promotion of Operands 46 The Comparison Operators 47 Ordinal Comparisons with <, <=, >, and >= 47 The instanceof Operator 48 The Equality Comparison Operators: == and!= 50 The Bitwise Operators: &, ^, and 51 Boolean Operations 54 The Short-Circuit Logical Operators 56 The Conditional Operator:?: 58 The Assignment Operators 59 An Assignment Has Value 60 Summary 61 Exam Essentials 63 Key Terms 64 Review Questions 65 Answers to Review Questions 68 Chapter 3 Modifiers 71 Modifier Overview 72 The Access Modifiers 72 public 73 private 73 Default 75 protected 76 Subclasses and Method Privacy 78 Summary of Access Modes 79 Other Modifiers 79 final 79 abstract 80 static 82 Static Initializers 85 native 85 transient 86 synchronized 87 volatile 87 Modifiers and Features 87 Summary 88 Exam Essentials 89 Key Terms 89 Review Questions 90 Answers to Review Questions 95
4276FM.fm Page xii Thursday, October 2, 2003 11:22 AM xii Chapter 4 Converting and Casting 97 Explicit and Implicit Type Changes 98 Primitives and Conversion 99 Primitive Conversion: Assignment 99 Assignment Conversion, Narrower Primitives, and Literal Values 102 Primitive Conversion: Method Call 103 Primitive Conversion: Arithmetic Promotion 103 Primitives and Casting 105 Object Reference Conversion 107 Object Reference Assignment Conversion 108 Object Method-Call Conversion 110 Object Reference Casting 111 Summary 115 Exam Essentials 115 Key Terms 116 Review Questions 117 Answers to Review Questions 121 Chapter 5 Flow Control, Assertions, and Exception Handling 123 The Loop Constructs 124 The while() Loop 124 The do Loop 126 The for() Loop 126 The break and continue Statements in Loops 129 The Selection Statements 131 The if()/else Construct 131 The switch() Construct 132 Exceptions 133 Flow of Control in Exception Conditions 133 Throwing Exceptions 137 Assertions 143 Assertions and Compilation 144 Runtime Enabling of Assertions 144 Using Assertions 144 Summary 146 Exam Essentials 147 Key Terms 148 Review Questions 149 Answers to Review Questions 156 Chapter 6 Objects and Classes 159 Benefits of Object-Oriented Implementation 160
4276FM.fm Page xiii Thursday, October 2, 2003 11:22 AM xiii Encapsulation 160 Re-use 162 Implementing Object-Oriented Relationships 162 Overloading and Overriding 163 Overloading Method Names 164 Method Overriding 166 Constructors and Subclassing 170 Overloading Constructors 172 Inner Classes 173 The Enclosing this Reference and Construction of Inner Classes 175 Member Classes 176 Classes Defined Inside Methods 177 Summary 183 Exam Essentials 183 Key Terms 184 Review Questions 185 Answers to Review Questions 190 Chapter 7 Threads 193 Thread Fundamentals 194 What a Thread Executes 195 When Execution Ends 197 Thread States 197 Thread Priorities 198 Controlling Threads 199 Yielding 199 Suspending 201 Sleeping 201 Blocking 202 Monitor States 204 Scheduling Implementations 204 Monitors, wait(), and notify() 205 The Object Lock and Synchronization 207 wait() and notify() 208 The Class Lock 213 Beyond the Pure Model 213 Deadlock 215 Another Way to Synchronize 217 Summary 218 Exam Essentials 219
4276FM.fm Page xiv Thursday, October 2, 2003 11:22 AM xiv Key Terms 220 Review Questions 221 Answers to Review Questions 225 Chapter 8 The java.lang and java.util Packages 227 The Object Class 228 The Math Class 229 The Wrapper Classes 231 Strings 234 The String Class 235 The StringBuffer Class 238 String Concatenation the Easy Way 240 The Collections API 241 Collection Types 242 Collections, Equality, and Sorting 244 The hashcode() Method 245 Collection Implementations in the API 246 Collections and Code Maintenance 247 Summary 253 Summary of Collections 254 Exam Essentials 254 Key Terms 255 Review Questions 256 Answers to Review Questions 259 Part II The Developer s Exam 261 Chapter 9 Taking the Developer s Exam 263 Are You Ready for the Exam? 264 Formalities of the Exam 266 Downloading the Assignment 266 Taking the Follow-up Exam 267 What the Assignment Covers 267 How the Assignment and Exam Are Graded 268 Structure of the Assignment 268 Code and APIs Provided 269 Example Assignment: Build a Trouble-Ticket System 270 GUI Development 272 Database/Server Development 273 Client-Server Logic 274 Coding Tips 275 Adhere to Supplied Naming 275
4276FM.fm Page xv Thursday, October 2, 2003 11:22 AM xv Stress Readability 275 Use Standard Design Patterns 276 Submission Requirements 276 Using javadoc 278 File Structure 279 Writing the README file 281 Using the JAR Tool 282 Preparation for the Follow-up Exam 284 What Are the Choices for Data Structures? 284 Is Implementing Runnable Better Than Extending Thread? 284 How Elaborate Should an Exception Class Structure Get? 285 How Many Ways Can You Set Up Listener Relationships? Which One Is Best? 285 How Do I Know Which Layout Manager to Use? 286 Which Design Patterns Are Most Useful in This Kind of Project? 287 When Does It Make Sense to Use protected and default Scope? 287 Doesn t an Abstract Class Let the Developer Specify More Behavior Than an Interface? 289 Summary 290 Exam Essentials 291 Key Terms 291 Review Questions 292 Answers to Review Questions 293 Chapter 10 Creating the User Interface with Swing 295 Defining the GUI s Requirements 297 Identifying Needed Components 297 Sketching the GUI 298 Isolating Regions of Behavior 299 Choosing Layout Managers 300 Common Swing Methods 300 getsize() and setsize() 301 getlocation() and setlocation() 301 setforeground() and setbackground() 301 setfont() 301 setenabled() 301 Basic Swing Components 302 Container Components 302 Ordinary Components 305 Menu Components 314 Building a JTable 316 Using AbstractTableModel 319
4276FM.fm Page xvi Thursday, October 2, 2003 11:22 AM xvi Building a JTree 323 JMenus and Actions 327 Panes 329 JSplitPane 330 JOptionPane 331 Summary 332 Exam Essentials 333 Key Terms 333 Review Questions 334 Answers to Review Questions 335 Chapter 11 Layout Managers 337 Layout Manager Theory 338 Component Size and Position 341 Layout Policies 343 The Flow Layout Manager 343 The Grid Layout Manager 345 The Border Layout Manager 347 The Card Layout Manager 354 The GridBag Layout Manager 359 Other Layout Options 374 Summary 375 Exam Essentials 375 Key Terms 376 Review Questions 377 Answers to Review Questions 378 Chapter 12 Writing the Network Protocol 379 Client-Server from Scratch 381 Server Operation 381 Connecting Clients to the Server 384 Communication Protocol 384 The Client Request Structure 387 Limitations of the Model 394 Remote Method Invocation (RMI) 395 A Model RMI Transaction 396 Implementing RMI 397 Limitations of RMI 401 More on Threads 402 Sharing Threads 403 Summary 410 Exam Essentials 410 Key Terms 411
4276FM.fm Page xvii Thursday, October 2, 2003 11:22 AM xvii Review Questions 412 Answers to Review Questions 413 Chapter 13 Connecting Client and Server 415 Events Basics 416 Event Naming Conventions 417 Event Notification 417 Using Java Bean Conventions 420 Java Beans and the MVC Design Pattern 423 Listeners 425 Remote Notification 432 Using Distributed Notification 434 Summary 435 Exam Essentials 435 Key Terms 436 Review Questions 437 Answers to Review Questions 438 Chapter 14 Enhancing and Extending the Database 439 Two-Tier Databases 440 Designing a Basic Scheme 441 Using Interfaces 442 Using Abstract Classes 447 Issues in Implementation 451 Exception Handling 451 Design Impediments 454 Thread Safety 456 Supporting New Features 459 Summary 460 Exam Essentials 460 Key Terms 461 Review Questions 462 Answers to Review Questions 463 Chapter 15 Building the Database Server 465 Database Requirements 466 Implementing RMI 467 Exporting with UnicastRemoteObject 471 Exporting an Activatable Object 475 Record Locking 479 Summary 481 Exam Essentials 482 Key Terms 482
4276FM.fm Page xviii Thursday, October 2, 2003 11:22 AM xviii Review Questions 483 Answers to Review Questions 484 Appendix A Practice Exam 485 Answers to Practice Exam 500 Glossary 505 Index 519