Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Ganesh_JavaSE7_Programming_1z0-804_study_guide.pdf
Скачиваний:
94
Добавлен:
02.02.2015
Размер:
5.88 Mб
Скачать

Contents

About the Authors xvii About the Technical Reviewer xix Acknowledgments xxi Introduction xxiii

Chapter 1: The OCPJP 7 Exam: FAQ

1 Oracle Java Certifications: Overview

......................................................................................................................................................

 

1

FAQ 1 What are the different levels of Oracle Java certification exams? ............................................................

1

FAQ 2 Can you compare the specifications of the 1Z0-803, 1Z0-804, and 1Z0-805 exams in relation

 

to OCAJP 7 and OCPJP 7 certification? ................................................................................................................

 

2

FAQ 3 OCAJP 7 certification is a prerequisite for OCPJP 7 certification via the 1Z0-804 exam

 

Does that mean that I have to take the OCAJP 7 exam before I can take the OCPJP 7 exam? ............................

4

FAQ 4 Is OCPJP 7 prerequisite for other Oracle certification exams? ..................................................................

4

FAQ 5 Should I take the OCPJP 7 or OCPJP 6 exam? ..........................................................................................

 

4

FAQ 6 How does the Oracle OCPJP 7 exam differ from the OCPJP 6 and OCPJP 5 exams

 

(and the previous Sun versions SCJP 6 and SCJP 5)? ..........................................................................................

 

4

The OCPJP 7 Exam .......................................................................................................................

 

5

FAQ 7 How many questions are there in the OCPJP 7 exam? .............................................................................

 

5

FAQ 8 What is the duration of the OCPJP 7 exam? ..............................................................................................

 

5

FAQ 9 What is the cost of the OCPJP 7 exam? ....................................................................................................

 

6

FAQ 10 What are the passing scores for the OCPJP 7 exam? .............................................................................

 

6

FAQ 11 What kinds of questions are asked in the OCPJP 7 exam? .....................................................................

6

FAQ 12 What does the OCPJP 7 exam test for? ...................................................................................................

 

6

FAQ 13 I’ve been a Java programmer for last five years Do I have to prepare for the OCPJP 7 exam? .............

7

FAQ 14 How do I prepare for the OCPJP 7 exam? ...............................................................................................

 

7

FAQ 15 How do I know when I’m ready to take the OCPJP 7 exam? ..................................................................

8

 

 

vii

Contents

Taking the OCPJP 7 Exam 8

FAQ 16. What are my options to register for the exam? 8

FAQ 17. How do I register for the exam, schedule a day and time for taking the exam, and appear

for the exam? 8 FAQ 18. What are the key things I need to remember before taking the exam and on the day of exam? 9

Chapter 2: Pretest 11

The OCPJP 7 Exam: Pretest 12 Answers with Explanations 36 Post-Pretest Evaluation 42

Chapter 3: Java Class Design 45

Essentials of OOP 46

FunPaint Application: An Example 46 Foundations of OOP 46

Class Fundamentals 48

Object Creation 49 Constructors 49 Access Modifiers 51

Overloading 55

Method Overloading 56 Constructor Overloading 57 Overload resolution 60 Points to Remember 63

Inheritance 63

Runtime Polymorphism 65 Type Conversions 74

Java Packages 77

Working with Packages 78

Summary 84

viii

Contents

Chapter 4: Advanced Class Design 87

Abstract Classes 87

Points to Remember 89

Using the “final” Keyword 90

Final Classes 90 Final Methods and Variables 91 Points to Remember 91

Using the “static” Keyword 92

Static Block 93 Points to Remember 94

Flavors of Nested Classes 94

Static Nested Classes (or Interfaces) 96 Inner Classes 97 Local Inner Classes 99 Anonymous Inner Classes 102

Enum Data Types 103

Points to Remember 106

Summary 111

Chapter 5: Object-Oriented Design Principles 113

Interfaces 113

Declaring and Using Interfaces 114 Abstract Classes vs. Interfaces 116

Object Composition 119

Composition vs. Inheritance 120

Design Patterns 123

The Singleton Design Pattern 128 The Factory Design Pattern 132 The Data Access Object (DAO) Design Pattern 139

Summary 145

ix

Contents

Chapter 6: Generics and Collections 147

Generics 148

Using Object Type and Type Safety 148 Using the Object Class vs. Generics 150 Creating Generic Classes 154 Diamond Syntax 157 Interoperability of Raw Types and Generic Types 158 Generic Methods 160 Generics and Subtyping 162 Wildcard Parameters 163 Points to Remember 170

The Collections Framework 171

Why Reusable Classes? 171 Basic Components of the Collections Framework 171 Algorithms (Collections Class) 192 The Arrays Class 195 Points to Remember 200

Summary 203

Generics 203 Collections Framework 204

Chapter 7: String Processing 205

Processing Strings 205

String Searching 205 String Parsing 208

Regular Expressions 211

Understanding regex Symbols 211 Regex Support in Java 212

String Formatting 218

Format Specifiers 218 Points to Remember 221

Summary 224

x

Contents

Chapter 8: Java I/O Fundamentals 225

Reading and Writing from Console 225

Understanding the Console Class 225

Using Streams to Read and Write Files 229

Character Streams and Byte Streams 230 Character Streams 230 Byte Streams 237

Points to Remember 246 Summary 249

Chapter 9: Java File I/O (NIO.2) 251

A Quick History of I/O APIs 251 Using the Path Interface 252

Getting Path Information 254 Comparing Two Paths 257

Using the Files Class 258

Checking File Properties and Metadata 259 Copying a File 264 Moving a File 265 Deleting a File 266

Walking a File Tree 267

Revisiting File Copy 270

Finding a File 271 Watching a Directory for Changes 273 Points to Remember 276 Summary 280

Chapter 10: Building Database Applications with JDBC 281

Introduction to JDBC 281

The Architecture of JDBC 282 Two-Tier and Three-Tier JDBC Architecture 283

xi

Contents

Types of JDBC Drivers 283 Setting Up the Database 284

Connecting to a Database Using a JDBC Driver 285

The Connection Interface 285 Connecting to the Database 286

Querying and Updating the Database 288

 Statement 288

Performing Transactions 300

The RowSet Interface 306

Summary 313

Define the Layout of the JDBC API 313 Connect to a Database by Using a JDBC driver 314 Update and Query a Database 314 Customize the Transaction Behavior of JDBC and Commit Transactions 315 Use the JDBC 4.1 RowSetProvider, RowSetFactory, and RowSet Interfaces 315

Chapter 11: Exceptions and Assertions 317

Introduction to Exception Handling 317

Throwing Exceptions 318 Unhandled Exceptions 319

Try-with-Resources 332

Closing Multiple Resources 333 Points to Remember 335

Exception Types 336

The Exception Class 336 The RuntimeException Class 338 The Error Class 341 The Throws Clause 343 Points to Remember 346

Custom Exceptions 347

xii

Contents

Assertions 350

Assert Statement 350 How Not to Use Asserts 352

Summary 358

Chapter 12: Localization 361

Introduction 362 Locales 362

The Locale Class 362

Resource Bundles 366

Using PropertyResourceBundle 367 Using ListResourceBundle 369

Loading a Resource Bundle 372

Naming Convention for Resource Bundles 372

Formatting for Local Culture 376

The NumberFormat Class 377 The DateFormat Class 381

Points to Remember 387 Summary 390

Chapter 13: Threads 393

Introduction to Concurrent Programming 393

Important Threading-Related Methods 394 Creating Threads 395 Asynchronous Execution 403

The States of a Thread 405

Two States in “Runnable” State 406

Concurrent Access Problems 407

Data Races 407 Thread Synchronization 408 Deadlocks 413

xiii

Contents

Other Threading Problems 415 The Wait/Notify Mechanism 416 More Thread States 425

Summary 433

Chapter 14: Concurrency 435

Using java.util.concurrent Collections 435

Semaphore 436 CountDownLatch 438 Exchanger 440 CyclicBarrier 442 Phaser 444 Concurrent Collections 447

Apply Atomic Variables and Locks 450

Atomic Variables 450 Locks 453 Conditions 456

Use Executors and ThreadPools 462

Executor 463 Callable, Executors, ExecutorService, ThreadPool, and Future 464 ThreadFactory 468 The ThreadLocalRandom Class 469 TimeUnit Enumeration 469

Use the Parallel Fork/Join Framework 470

Useful Classes of the Fork/Join Framework 471 Using the Fork/Join Framework 472

Points to Remember 478 Summary 482

xiv

Contents

Chapter 15: OCPJP 7 Quick Refresher 485

Chapter 3: Java Class Design 486 Chapter 4: Advanced Class Design 487 Chapter 5: Object-Oriented Design Principles 488 Chapter 6: Generics and Collections 489 Chapter 7: String Processing 491 Chapter 8: Java I/O Fundamentals 493 Chapter 9: Java File I/O (NIO.2) 494 Chapter 10: Building Database Applications with JDBC 496 Chapter 11: Exceptions and Assertions 499 Chapter 12: Localization 501 Chapter 13: Threads 503 Chapter 14: Concurrency 504

Appendix A: Exam Topics 507

OCPJP7 Exam (1Z0-804 a.k.a. Java SE 7 Programmer II) Topics 507

1. Java Class Design (G&S Chapter 3) 507 2. Advanced Class Design (G&S Chapter 4) 508 3. Object-Oriented Design Principles (G&S Chapter 5) 508 4. Generics and Collections (G&S Chapter 6) 508 5. String Processing (G&S Chapter 7) 508 6. Exceptions and Assertions (G&S Chapter 11) 509 7. Java I/O Fundamentals (G&S Chapter 8) 509 8. Java File I/O (NIO.2) (G&S Chapter 9) 509 9. Building Database Applications with JDBC (G&S Chapter 10) 509 10. Threads (G&S Chapter 13) 509 11. Concurrency (G&S Chapter 14) 510 12. Localization (G&S Chapter 12) 510

xv

Contents

OCPJP 7 Exam (1Z0-805, a.k.a. Upgrade to Java SE 7 Programmer) Topics 510

1. Language Enhancements (G&S Chapters 6, 11) 510

2. Design Patterns (G&S Chapter 5) 510 3. Database Applications with JDBC (G&S Chapter 10) 511 4. Concurrency (G&S Chapters 13, 14) 511 5. Localization (G&S Chapter 12) 511 6. Java File I/O (NIO.2) (G&S Chapter 9) 511

Appendix B: Mock Test – 1 513

Answer Sheet 555 Answers and Explanations 556

Appendix C: Mock Test – 2 569

Answer Sheet 606 Answers and Explanations 607

Index 619

xvi

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]