1. Trang chủ
  2. » Công Nghệ Thông Tin

OCA java SE 7 programmer i certification guide

562 1,1K 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 562
Dung lượng 18,92 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

35 ■ Importing classes from the default package 36 ■ Static imports 36 1.4 Java access modifiers 37 Access modifiers 37 ■ Public access modifier 39 Protected access modifier 40 ■ Defaul

Trang 1

Mala Gupta

FOREWORD BY Jeanne Boyarsky

Prepare for the 1ZO-803 exam

Trang 2

OCA Java SE 7 Programmer I Certification Guide

Trang 4

OCA Java SE 7

Programmer I Certification Guide

MALA GUPTA

M A N N I N G

SHELTER ISLAND

Trang 5

For online information and ordering of this and other Manning books, please visit

www.manning.com The publisher offers discounts on this book when ordered in quantity For more information, please contact

Special Sales Department

Manning Publications Co

20 Baldwin Road

PO Box 261

Shelter Island, NY 11964

Email: orders@manning.com

©2013 by Manning Publications Co All rights reserved

No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in the book, and Manning

Publications was aware of a trademark claim, the designations have been printed in initial caps

or all caps

Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end Recognizing also our responsibility to conserve the resources of our planet, Manning booksare printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine

Manning Publications Co Development editor: Cynthia Kane

20 Baldwin Road Technical editor: Brent Watson

PO Box 261 Technical proofreader: Jeanne Boyarsky

Shelter Island, NY 11964 Copyeditors: Tara Walsh, Bob Herbstman,

Nancy Wolfe KotaryProofreader: Andy CarrollTypesetter: Dennis DalinnikIllustrator: Martin MurtonenCover designer: Marija Tudor

ISBN: 9781617291043

Printed in the United States of America

1 2 3 4 5 6 7 8 9 10 – MAL – 19 18 17 16 15 14 13

Trang 6

To my pillar of strength, my best friend, and my husband, Dheeraj Prakash

Trang 8

brief contents

Introduction 1

1 ■ Java basics 13

2 ■ Working with Java data types 69

3 ■ Methods and encapsulation 110

4 ■ String, StringBuilder, Arrays, and ArrayList 174

Trang 10

about this book xxiii

about the author xxx

about the cover illustration xxxi

Introduction 1

1 Disclaimer 2

2 Introduction to OCA Java SE 7 Programmer

certification 2

The importance of OCA Java SE 7 Programmer certification 2

Comparing OCA Java exam versions 3Comparing the OCA

Java SE 7 Programmer I (1Z0-803) and OCP Java SE 7

Programmer II (1Z0-804) exams 4Complete exam objectives, mapped to book chapters, and readiness checklist 4

3 FAQs 8

FAQs on exam preparation 8FAQs on taking the exam 10

4 The testing engine used in the exam 12

Trang 11

1 Java basics 13

1.1 The structure of a Java class and source code file 14

Structure of a Java class 15Structure and components of

a Java source code file 21

1.2 Executable Java applications 25

Executable Java classes versus nonexecutable Java classes 25 Main method 26

1.3 Java packages 29

The need for packages 29Defining classes in a package using the package statement 30Using simple names with import statements 32Using packaged classes without using the import statement 34Importing a single member versus all members of a package 35Can you recursively import subpackages? 35Importing classes from the

default package 36Static imports 36

1.4 Java access modifiers 37

Access modifiers 37Public access modifier 39 Protected access modifier 40Default access (package access) 42 Private access modifier 45

1.5 Nonaccess modifiers 47

Abstract modifier 48Final modifier 49Static modifier 51

1.6 Summary 54 1.7 Review notes 55 1.8 Sample exam questions 58 1.9 Answers to sample exam questions 62

2 Working with Java data types 69

Valid and invalid identifiers 81

2.3 Object reference variables 82

What are object reference variables? 82Differentiating between object reference variables and primitive variables 84

Trang 12

2.4 Operators 85

Assignment operators 87Arithmetic operators 89 Relational operators 92Logical operators 94 Operator precedence 96

2.5 Summary 98

2.6 Review notes 98

2.7 Sample exam questions 101

2.8 Answers to sample exam questions 104

3 Methods and encapsulation 110

3.1 Scope of variables 112

Local variables 112Method parameters 114 Instance variables 115Class variables 116 Overlapping variable scopes 117

3.2 Object’s life cycle 120

An object is born 120Object is accessible 122 Object is inaccessible 123

3.3 Create methods with arguments and return values 124

Return type of a method 125Method parameters 127 Return statement 130

3.4 Create an overloaded method 132

Argument list 133Return type 135Access modifier 135

3.5 Constructors of a class 136

User-defined constructors 137Default constructor 140 Overloaded constructors 142

3.6 Accessing object fields 145

What is an object field? 145Read and write object fields 145 Calling methods on objects 148

3.7 Apply encapsulation principles to a class 150

Need for encapsulation 150Apply encapsulation 151

3.8 Passing objects and primitives to methods 153

Passing primitives to methods 153Passing object references

to methods 155

3.9 Summary 158

3.10 Review notes 158

Trang 13

3.11 Sample exam questions 162 3.12 Answers to sample exam questions 166

4 String, StringBuilder, Arrays, and ArrayList 174

4.1 Welcome to the world of the String class 175

Creating String objects 176The class String is immutable 179 Methods of the class String 182String objects

and operators 186Determining equality of Strings 187

4.2 Mutable strings: StringBuilder 189

The StringBuilder class is mutable 190 Creating StringBuilder objects 190Methods of class StringBuilder 192A quick note on the class StringBuffer 197

4.3 Arrays 197

What is an array? 197Array declaration 199 Array allocation 200Array initialization 201 Combining array declaration, allocation, and initialization 203 Asymmetrical multidimensional arrays 204Arrays of type interface, abstract class, and class Object 205Members of

an array 206

4.4 ArrayList 206

Creating an ArrayList 207Adding elements to

an ArrayList 209Accessing elements of an ArrayList 211 Modifying the elements of an ArrayList 212Deleting the elements of an ArrayList 213Other methods of ArrayList 215

4.5 Comparing objects for equality 221

The method equals in the class java.lang.Object 221 Comparing objects of a user-defined class 221Incorrect method signature of the equals method 223Contract of the

equals method 224

4.6 Summary 225 4.7 Review notes 227 4.8 Sample exam questions 232 4.9 Answers to sample exam questions 236

5 Flow control 243

5.1 The if and if-else constructs 245

The if construct and its flavors 245Missing else blocks 248 Implications of the presence and absence of {} in

Trang 14

if-else constructs 249Appropriate versus inappropriate expressions passed as arguments to an if statement 251 Nested if constructs 252

5.2 The switch statement 254

Create and use a switch statement 254Comparing a switch statement with multiple if-else constructs 254Arguments passed

to a switch statement 257Values passed to the label case of a switch statement 258Use of break statements within

a switch statement 259

5.3 The for loop 260

Initialization block 262Termination condition 263 The update clause 263Nested for loop 264

5.4 The enhanced for loop 265

Limitations of the enhanced for loop 268Nested enhanced for loop 269

5.5 The while and do-while loops 270

The while loop 271The do-while loop 272 While and do-while block, expression, and nesting rules 274

5.6 Comparing loop constructs 274

Comparing do-while and while loops 274Comparing for and enhanced for loops 275Comparing for and while loops 276

5.7 Loop statements: break and continue 276

The break statement 276The continue statement 278 Labeled statements 279

5.8 Summary 280

5.9 Review notes 280

5.10 Sample exam questions 283

5.11 Answers to sample exam questions 287

6 Working with inheritance 295

6.1 Inheritance with classes 296

Need to inherit classes 296A derived class contains within it an object of its base class 300Which base class members are inherited

by a derived class? 301Which base class members aren’t inherited by a derived class? 301Derived classes can define additional properties and behavior 301Abstract base class versus concrete base class 302

Trang 15

6.2 Use interfaces 304

Properties of members of an Interface 307Why a class can’t extend multiple classes 308Implementing multiple interfaces 308

6.3 Reference variable and object types 310

Using a variable of the derived class to access its own object 311 Using a variable of the base class to access an object of

a derived class 312Using a variable of an implemented interface

to access a derived class object 312The need for accessing an object using the variables of its base class or implemented interfaces 313

6.4 Casting 316

How to cast a variable to another type 316 Need for casting 318

6.5 Use this and super to access objects and constructors 319

Object reference: this 319Object reference: super 321

7 Exception handling 348

7.1 Exceptions in Java 349

A taste of exceptions 349Why handle exceptions separately? 352Do exceptions offer any other benefits? 353

7.2 What happens when an exception is thrown? 354

Creating try-catch-finally blocks 356Will a finally block execute even if the catch block defines a return statement? 361

What happens if both a catch and a finally block define return statements? 362What happens if a finally block modifies the value returned from a catch block? 363Does the order of the exceptions caught in the catch blocks matter? 364Can I rethrow

an exception or the error I catch? 366Can I declare my methods

to throw a checked exception, instead of handling it? 367

Trang 16

7.4 Common exception classes and categories 374

ArrayIndexOutOfBoundsException and IndexOutOfBoundsException 375ClassCastException 376 IllegalArgumentException 378IllegalStateException 378 NullPointerException 379NumberFormatException 382 ExceptionInInitializerError 384StackOverflowError 386 NoClassDefFoundError 386OutOfMemoryError 387

7.5 Summary 387

7.6 Review notes 388

7.7 Sample exam questions 393

7.8 Answers to sample exam questions 397

8.1 Mock exam 405

8.2 Answers to mock exam questions 439

appendix Answers to Twist in the Tale exercises 502

index 519

Trang 18

foreword

Taking the OCA Java Programmer I exam is a bit like taking a driving test First youlearn the basics, like where the brakes are Then you start driving, and then you getready to take the driving test to get your license The written test includes things every-one should know, things that you’ll never use after the road test, and some things thatare tricky edge cases While the programmer exam cares about breaks more thanbrakes, it certainly likes edge cases!

Consider Mala Gupta your driving instructor to get you ready for the programmerexam Mala points out what you’ll need to know when programming in the realworld—on your first job

And consider this book your driver’s manual It gives you the rules of the road ofJava, plus the gotchas that show up on that pesky written test But don’t worry, it ismuch more fun to read this book than the driver’s manual Just like the driver’s man-ual won’t teach you everything about driving, this book won’t teach you everythingthere is to know about Java If you haven’t yet, read an intro to a Java book first Start

with a book like Head First Java or Thinking in Java and then come back to this book to

study for the exam

As the technical proofreader of this book, I got to see it evolve and get better asMala worked on it Through the conversations we had on little things, I learned thatMala knows her stuff and is a great teacher of Java While I’ve only technical proofread

a handful of books, I’ve posted reviews of over 150 technical books on Amazon, whichmakes it easy to spot a book that isn’t clear or helpful I’m happy to say that Mala’sexplanations are all very clear, and the pointers are great

Trang 19

I also got to read Mala’s posts in the certification forums at coderanch.com She’sbeen sharing updates about the exam as it comes out and posting fairly regularly forover a year As a senior moderator at coderanch.com, it is great to see an author sharingher wisdom It’s also nice to see the similarity in writing style between the forum postsand the book This shows the book is readable and written in an easy-to-understand,casual style

I particularly liked the diagrams, flow charts, and cartoons in this book And, ofcourse, the annotated code examples I’ve come to expect from any Manning book.Each chapter ends with sample mock exam questions and there is a full mock exam atthe end This gives you good practice in getting ready for the exam Wrong answersare well explained so you don’t make the same mistakes over and over

My favorite part of the book is the “Twist in the Tale” exercises Mala gives a ber of examples of how making a seemingly minor change to the code can have majorconsequences These exercises develop your attention to detail so you are more obser-vant for the mock exam questions and the exam itself

I had already passed the OCA Java Programmer exam with a score of 98% beforereading this book If I hadn’t, the questions would have prepared me for the exam.Studying from this book will give you the skills and confidence you need to become anOracle Certified Associate Java Programmer Happy coding and good luck on the exam!

JEANNE BOYARSKY

SENIOR DEVELOPER & MODERATOR

CODERANCH

Trang 20

preface

Java programmer certifications are designed to tell would-be employers whether youreally know your stuff, and cracking the OCA Java SE 7 Programmer Certification isnot an easy task Thorough preparation is crucial if you want to pass the exam the firsttime with a score that you can be proud of You need to know Java inside and out, andyou need to understand the certification process so that you’re ready for the challeng-ing questions you’ll face in the exam

This book is a comprehensive guide to the 1Z0-803 exam You’ll explore a widerange of important Java topics as you systematically learn how to pass the certificationexam Each chapter starts with a list of the exam objectives covered in that chapter.Throughout the book you’ll find sample questions and exercises designed to rein-force key concepts and prepare you for what you’ll see in the real exam, along withnumerous tips, notes, and visual aids

Unlike many other exam guides, this book provides multiple ways to digest tant techniques and concepts, including comic conversations, analogies, pictorial rep-resentations, flowcharts, UML diagrams, and, naturally, lots of well-commented code.The book also gives insight into typical exam question mistakes and guides you inavoiding traps and pitfalls It provides

impor-■ 100% coverage of exam topics, all mapped to chapter and section numbers

■ Hands-on coding exercises, including particularly challenging ones that throw

in a twist

Trang 21

■ Instruction on what’s happening behind the scenes using the actual code fromthe Java API source

■ Mastery of both the concepts and the exam

This book is written for developers with a working knowledge of Java My hope is thatthe book will deepen your knowledge, prepare you well for the exam, and that youwill pass it with flying colors!

Trang 22

acknowledgments

First and foremost, I thank Dheeraj Prakash—my pillar of strength, my best friendand my husband This book wouldn’t exist without his efforts His constant guidance,encouragement, and love kept me going He helped me to get started with this bookand got me over the goal line

My sincere gratitude to Marjan Bace, publisher at Manning, for giving me the tunity to author this book The Manning team has been wonderful—Scott Meyersensured that it was worth it for Manning to have a book on this subject Cynthia Kane,

oppor-my development editor, played a major role in shaping the organization of individualchapters and the overall book It has been a real pleasure to work with her CopyeditorsTara Walsh, Bob Herbstman, and Nancy Wolfe Kotary not only applied their magic tosentence and language constructions but also supplemented their editing with valuablesuggestions on technical content

Technical Editor Brent Watson did a brilliant job of reviewing the complete book tents in a limited time, catching even the smallest errors in the book Technical Proof-reader Jeanne Boyarsky was outstanding and an amazing person to work with She wasvery quick at reviewing the book, with an eye for detail Proofreader Andy Carroll wasextremely capable and talented He reviewed the final manuscript with great precision The technical reviewers on this book did an awesome job of reviewing the con-tents and sharing their valuable feedback and comments: Roel De Nijs, Ivan Todorovic,Michael Piscatello, Javier Valverde, Anayonkar Shivalkar, Kyle Smith, Niklas Rosencrantz,Ashwin Mhatre, Janki Shah, Dmitriy Andrushko, Nitesh Nandwana, and PriyankaManchanda I would also like to thank Ozren Harlovic, Review Editor, for managing

Trang 23

I thank the MEAP readers for buying the book while it was being developed and fortheir suggestions, corrections, and encouragement: Samuel Prette, David C., DiegoPoggioli, Baptize, Jayagopi Jagadeesan, David Vonka, Joel Rainey, Steve Breese, andJörgen Persson.

I would also like to thank my former colleagues Harry Mantheakis, Paul Rosenthal,and Selvan Rajan, whose names I use in coding examples throughout the book I havealways looked up to them

I thank my nine-year-old daughter, Shreya, an artist, who often advised me on theimages that I created for the book I’m also grateful to my younger daughter, Pavni,who patiently waited for my attention all these months when my focus was on thebook I thank my family for their unconditional support The book would have beennot been possible without their love and encouragement

Trang 24

about this book

This book is written for developers with a working knowledge of Java who want to earnthe OCA Java SE 7 Programmer certification It uses powerful tools and features tomake reaching your goal of certification a quick, smooth, and enjoyable experience.This section will explain the features used in the book and tell you how to use thebook to get the most out of it as you prepare for the certification exam More informa-tion on the exam and on how the book is organized is available in the Introduction

Start your preparation with the chapter-based exam

objective map

I strongly recommend a structured approach to preparing for this exam To help youwith this task, I’ve developed a chapter-based exam objective map, as shown in figure 1.The full version is in the Introduction (table I.3)

Figure 1 The Introduction to this book provides a list of all exam objectives and the corresponding chapter and section numbers where they are covered See the full table in the Introduction (table I.3).

Trang 25

As you go through your preparation, mark your readiness score for each section assessment is an important tool that will help you determine when you are ready totake the exam

The map in the Introduction shows the complete exam objective list mapped tothe relevant chapter and section numbers You can jump to the relevant section num-ber to work on a particular exam topic

Chapter-based objectives

Each chapter starts with a list of the exam objectives covered in that chapter, as shown

in figure 2 This list is followed by a quick comparison of the major concepts and ics covered in the chapter with real-world objects and scenarios

Exam tips

Each chapter provides multiple exam tips to re-emphasize the points that are the most

confusing, overlooked, or frequently answered incorrectly by candidates and thattherefore require special attention for the exam Figure 4 shows an example

Figure 2 An example of the list of exam objectives and brief explanations at the beginning of each chapter

Figure 3 An example of the beginning of a section, identifying the exam objective that it covers

Trang 26

Simple images are used to draw your attention to a particular line of code (asshown in figure 7).

Figure 4 Example of an exam tip; they occur multiple times in a chapter

Figure 5 Example note

Figure 6 Example sidebar

Trang 27

Fig-Figure 7 An example image that draws your attention to a particular line of code

Figure 8 An example pictorial representation of data in an array

Figure 9 An example of a little humor to help you remember that the finally block

always executes

public String replace(char oldChar, char newChar) {

if (oldChar != newChar) {

// code to create a new char array and

// replace the desired char with the new char

return new String(0, len, buf);

multiStrArr

null

0 1 2 0 1

0 1

Trang 28

The exam requires that you know multiple methods from classes such as String,StringBuilder, ArrayList, and others The number of these methods can be over-whelming, but grouping these methods according to their functionality can make thistask a lot more manageable Figure 12 shows an example of an image that groupsmethods of the String class according to their functionality.

Figure 10 An example of grouping and representing information for quick reference

Figure 11 An example pictorial representation of steps executed by the Java compiler

when it compiles a class without a constructor

Figure 12 An example image used to group methods of the String class according to their functionality.

int age;

Employee() { super();

name = null;

age = 0;

} }

Poor class Employee doesn’t have a constructor.

Let me create one for it.

Default constructor

Java compiler In

Out

String methods

Query position of chars

substring indexOf

Seem to modify String Others

Trang 29

Expressions that involve multiple operands can be hard to comprehend Figure 13 is

an example of an image that can save you from the mayhem of unary increment anddecrement operators used in prefix and postfix notation

Code snippets that define multiple points and that may result in the nonlinear tion of code can be very difficult to comprehend These may include selection state-ments, loops, or exception-handling code Figure 14 is an example of an image thatclearly outlines the lines of code that will execute

execu-Twist in the Tale exercises

Each chapter includes a few Twist in the Tale exercises For these exercises, I’ve tried

to use modified code from the examples already covered in a chapter, and the “Twist

in the Tale” title refers to modified or tweaked code These exercises highlight how

a = a++ + a + a - a + ++a;

Value of a will increment after

this current value is used.

Since this is again a postfix notation value 11 is used before the decrement.

The value of a decrements to 9 due to a here, but again increments to 10 due to ++a.

Value of a increments to 11 due

to postfix ++ used prior to this.

Value of a decrements to 10 due to postfix used prior to this.

Figure 13 Example of values taken by the operands during execution of an expression

Figure 14 An example of flow of control in a code snippet that may define multiple points of

nonlinear execution of code

1> RiverRafting riverRafting = new RiverRafting();

7> catch (FallingRiverException e1) {

8> System.out.println("Get back in the raft");

9> }

10> catch (DropOarException e2) {

11> System.out.println("Do not panic");

12> }

13> finally {

14> System.out.println("Pay for the sport");

15> }

16> System.out.println("After the try block");

1 Execute code on line 3.

Code on line 4 and 5 won't execute if line 3 throws an exception.

2 Combat exception thrown by code on line 3 Execute exception handler for

FallInRiverException.

3 finally block always executes, whether line 3 throws any exception or not.

4 Control transfers to the statement following the try catch finally - - block.

Trang 30

Code Indentation

Some of the examples in this book show incorrect indentation of code This has beendone on purpose because on the real exam you can't expect to see perfectly indentedcode You should be able to comprehend incorrectly indented code to answer anexam question correctly

Review notes

When you’re ready to take your exam, don’t forget to reread the review notes a daybefore or on the morning of the exam These notes contain important points fromeach chapter as a quick refresher

Exam questions

Each chapter concludes with a set of 10 to 11 exam questions These follow the same tern as the real exam questions Attempt these exam questions after completing a chapter

pat-Answers to exam questions

The answers to all exam questions provide detailed explanations, including why optionsare correct or incorrect Mark your incorrect answers and identify the sections thatyou need to reread If possible, draw a few diagrams—you’ll be amazed at how muchthey can help you retain the concepts Give it a try—it’ll be fun!

Author Online

The purchase of OCA Java SE 7 Programmer I Certification Guide includes free access to a

pri-vate forum run by Manning Publications where you can make comments about the book,ask technical questions, and receive help from the author and other users You can accessand subscribe to the forum at www.manning.com/OCAJavaSE7ProgrammerICertification-Guide This page provides information on how to get on the forum once you’re registered,what kind of help is available, and the rules of conduct in the forum

Manning’s commitment to our readers is to provide a venue where a meaningfuldialogue among individual readers and between readers and the author can takeplace It’s not a commitment to any specific amount of participation on the part of theauthors, whose contribution to the book’s forum remains voluntary (and unpaid) Wesuggest you try asking the author some challenging questions, lest her interest stray! The Author Online forum and the archives of previous discussions will be accessi-ble from the publisher’s website as long as the book is in print

Trang 31

about the author

Mala Gupta has a Master’s degree in Computer Applications (MCA) She is an OracleCertified Associate-Java SE 7 Programmer, Java Sun Certified Web Component Devel-oper (SCWCD), and Sun Certified Java 2 Programmer (SCJP)

She has more than 12 years of experience in software design and development andtraining Her work experience is in Java technologies, primarily as an analyst, pro-grammer, and mentor

Mala has worked with international training and software services organizations inEurope and development centers in India on various Java-based portals and web appli-cations She has experience in mentoring and ramping up teams’ technical and pro-cess skills

She is the founder and lead mentor of a portal (http://ejavaguru.com) that hasoffered an online Java course in Java Programmer certification since 2006

Trang 32

about the cover illustration

The figure on the cover of the OCA Java SE 7 Programmer I Certification Guide is captioned

a “Morlach.” This illustration is taken from a recent reprint of Balthasar Hacquet’s

Images and Descriptions of Southwestern and Eastern Wenda, Illyrians, and Slavs published

by the Ethnographic Museum in Split, Croatia, in 2008 Hacquet (1739–1815) was anAustrian physician and scientist who spent many years studying the botany, geology,and ethnography of many parts of the Austrian Empire, as well as the Veneto, theJulian Alps, and the western Balkans, inhabited in the past by peoples of many differ-ent tribes and nationalities Hand-drawn illustrations accompany the many scientificpapers and books that Hacquet published

Morlachs were a rural population that lived in the Dinaric Alps in the western kans hundreds of years ago Many of them were shepherds who migrated in search ofbetter pastures for their flocks, alternating between the mountains in the summer andthe seashore in the winter They were also called “Vlachs” in Serbian and Croatian.The rich diversity of the drawings in Hacquet’s publications speaks vividly ofthe uniqueness and individuality of Alpine and Balkan regions just 200 years ago Thiswas a time when the dress codes of two villages separated by a few miles identified peo-ple uniquely as belonging to one or the other, and when members of an ethnictribe, social class, or trade could be easily distinguished by what they were wearing Dress codes have changed since then and the diversity by region, so rich at thetime, has faded away It is now often hard to tell the inhabitant of one continent fromanother and the residents of the picturesque towns and villages in the Balkans are notreadily distinguishable from people who live in other parts of the world

Trang 33

We at Manning celebrate the inventiveness, the initiative, and the fun of the puter business with book covers based on costumes from two centuries ago broughtback to life by illustrations such as this one

Trang 34

Introduction

This book is intended specifically for individuals who wish to earn the Oracle fied Associate (OCA) Java SE 7 Programmer certification (exam number 1Z0-803) Itassumes that you are familiar with Java and have some experience working with it

Certi-This introduction covers

■ Introduction to the Oracle Certified Associate (OCA)

Java SE 7 Programmer certification (exam number 1Z0-803)

■ Importance of OCA Java SE 7 Programmer certification

■ Comparison of the OCA Java SE 7 Programmer I exam with

OCA Java SE 5/6 exam

■ Comparison of the OCA Java SE 7 Programmer I exam

(1Z0-803) with OCP Java SE 7 Programmer II exam

(1Z0-804)

■ Detailed exam objectives, mapped to book chapters

■ Readiness checklist to determine your readiness level for

writing the exam

■ FAQ on exam preparation and on taking the exam

■ Introduction to the testing engine used for the exam

Trang 35

to change per Oracle’s policies The author and publisher of the book shall not beheld responsible for any loss or damage accrued due to any information contained inthis book or due to any direct or indirect use of this information.

certification

The Oracle Certified Associate (OCA) Java SE 7 Programmer I exam (1Z0-803) coversthe fundamentals of Java SE 7 programming, such as the importance of object-oriented programming, its implementation in code, and using flow control, arrays,and other constructs

This exam is the first of the two steps in earning the title of Oracle Certified sional (OCP) Java SE 7 Programmer It certifies that an individual possesses a strongfoundation in the Java programming language Table 1 lists the details of this exam

Profes-2.1 The importance of OCA Java SE 7 Programmer certification

The OCA Java SE 7 Programmer I exam (1Z0-803) is an entry-level exam in your Javacertification roadmap, as shown in figure 1 This exam is a prerequisite for the OCPJava SE 7 Programmer II exam (1Z0-804), which is itself a prerequisite for most of theother Oracle certifications in Java The dashed lines and arrows in figure 1 depictthe prerequisites for a certification

As shown in figure 1, the Java certification tracks are offered under the categoriesAssociate, Professional, Expert, and Master

Table 1 Details for OCA Java SE 7 Programmer I exam (1Z0-803)

Trang 36

Introduction

2.2 Comparing OCA Java exam versions

This section will clear up any confusion surrounding the different versions of the OCAJava exam As of now, Oracle offers two versions of the OCA certification in Java:

■ OCA Java SE 7 Programmer I (exam number: 1Z0-803)

■ OCA Java SE 5/SE 6 (exam number: 1Z0-850)

These two exam versions are quite different as far target audience, total number ofquestions, passing score, and exam duration are concerned, as listed in table 2

Java SE 7 Java SE 7

Java SE 6/5

Java SE 6 Developer

Java EE 5 Enterprise Architect

Java EE 5 Web Component Developer

Java EE 6 Web Component Developer

Java EE 6 Enterprise JavaBeans Developer

Java EE 6 Web Services Developer

Java EE 6 Java Persistence API Developer

Java ME Mobile Application Developer

Java EE 5 Business Component Developer

Increasing difficulty level

Figure 1 OCA Java SE 7 Programmer certification is the entry-level certification in the Java certification roadmap It’s a prerequisite for the OCP Java SE 7 Programmer II exam (1Z0-804), which is a prerequisite for most of the other certifications in Java.

Trang 37

4 Introduction

Figure 2 shows a detailed comparison of the exam objectives of OCA Java SE 5/6 (1Z0

-850) and OCA Java SE 7 Programmer I (1Z0-803) It shows objectives that are exclusive

to each of these exam versions and those that are common to both The first columnshows the objectives that are included only in OCA Java SE 5/6 (1Z0-850), the middlecolumn shows common exam objectives, and the right column shows exam objectivescovered only in OCA Java SE 7 Programmer I (1Z0-803)

2.3 Comparing the OCA Java SE 7 Programmer I (1Z0-803) and OCP

Java SE 7 Programmer II (1Z0-804) exams

The confusion between these two exams is due to the similarity in their names, butthese are two separate exams Starting with Java 7, Oracle has raised the bar to earnthe title of Oracle Certified Professional Java SE 7 Programmer, which now requiressuccessfully completing the following two exams:

■ OCA Java SE 7 Programmer I (exam number: 1Z0-803)

■ OCP Java SE 7 Programmer II (exam number: 1Z0-804)

The OCP Java SE 7 Programmer certification is designed for individuals who possessadvanced skills in the Java programming language This certification covers compara-tively advanced Java features, such as threads, concurrency, Java file I/O, inner classes,localization, and others

2.4 Complete exam objectives, mapped to book chapters, and

readiness checklist

Table 3 includes a complete list of exam objectives for the OCA Java SE 7 Programmer

I exam, which was taken from Oracle’s website All the objectives are mapped to thebook’s chapters and the section numbers that cover them You can also check yourreadiness to take the exam by selecting the appropriate stars Here’s the legend:

! Basic knowledge

!! Intermediate (you can use it in code)

!!! Advanced (you can answer all questions about it)

Table 2 Comparing exams: OCA Java SE 7 Programmer I and OCA Java SE 5/6

OCA Java SE 7 Programmer I (1Z0-803) OCA Java SE 5/SE 6 (1Z0-850)

Target audience Java programmers Java programmers and IT managers Java version Based on Java version 7 Based on Java version 5/6

Trang 38

Java development fundamentals

Java platforms and

• Test equality between String and other objects using == and equals()

• ArrayList

• One-dimensional arrays

• Multidimensional arrays

• for and enhanced for loops

• while and do while - loops

• break and continue statements

• Create methods with arguments and return types

• Apply access modifiers

• Effect on object references and primitives when they are passed to methods

• Implement inheritance

• Polymorphism

• Differentiate between type of

a reference variable and object

• Use abstract classes and interfaces

• Determine when casting is necessary

• Use super and this to access objects and constructors

• Apply static keyword to methods and fields

• Overloaded constructors and methods

• Default and user-defined constructors

• Use of javac command

• Use of java command

• Purpose and type of classes

• Structure of Java class

• import and package statements

• main method

• Primitives, object references

• Read/write to object fields

• Call methods on objects

• Exceptions and errors

• try catch - blocks

• Use of exceptions

• Methods that throw exceptions

• Common exception classes and categories

• EJB, servlets, JSP, JMS, SMTP,

JAX-RBC, WebServices, JavaMail

• Servlet and JSP for HTML

• EJB session, entity, and

• Compare and contrast

J2SE, J2ME, J2EE

• RMI

• JDBC, SQL, RDMS

• JNDI, messaging, and JMS

Working with Java data types

Operators and decision constructs

Creating and using arrays

Methods and encapsulation

Inheritance

Figure 2 Comparing objectives of exams OCA Java SE 5/6 and OCA Java SE 7 Programmer I

Trang 39

6 Introduction

Table 3 Exam objectives and subobjectives mapped to chapter and section numbers,

with readiness score

Exam objectives Covered in chapter/section Your readiness score

1.2 Define the structure of a Java class Section 1.1 !!!

1.3 Create executable Java applications with

a main method

1.4 Import other Java packages to make them

accessible in your code

2 Working with Java data types Chapters 2, 3, and 4

2.1 Declare and initialize variables Sections 2.1 and 2.3 !!!

2.2 Differentiate between object reference

variables and primitive variables

Sections 2.1 and 2.3 !!!

2.4 Explain an object’s life cycle Section 3.2 !!!

2.6 Manipulate data using the

String-Builder class and its methods

3 Using operators and decision constructs Chapters 2, 4, and 5

3.2 Use parentheses to override operator

precedence

3.3 Test equality between strings and other

objects using == and equals()

3.4 Create if and if - else constructs Section 5.1 !!!

4 Creating and using arrays Chapter 4

4.1 Declare, instantiate, initialize, and use a

Trang 40

Introduction to OCA Java SE 7 Programmer certification

5.2 Create and use for loops, including the

enhanced for loop

Sections 5.3 and 5.4 !!!

5.3 Create and use do - while loops Section 5.5 !!!

6 Working with methods and

6.4 Differentiate between default and

user-defined constructors

6.5 Create and overload constructors Section 3.5 !!!

6.7 Apply encapsulation principles to a class Section 3.7 !!!

6.8 Determine the effect upon object

refer-ences and primitive values when they

are passed into methods that change

the values

7 Working with inheritance Chapters 1 and 6

7.2 Develop code that demonstrates the use

of polymorphism

7.3 Differentiate between the type of a

refer-ence and the type of an object

7.4 Determine when casting is necessary Section 6.4 !!!

7.5 Use super and this to access objects

and constructors

7.6 Use abstract classes and interfaces Sections 1.5, 6.2, and 6.6 !!!

Table 3 Exam objectives and subobjectives mapped to chapter and section numbers,

with readiness score (continued)

Exam objectives Covered in chapter/section Your readiness score

Ngày đăng: 31/08/2016, 15:12

TỪ KHÓA LIÊN QUAN