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

Manning OCA java SE 8 programmer i certification guide

706 890 1

Đ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 706
Dung lượng 17,79 MB

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

Nội dung

1.1 The structures of a Java class and a source code file 23 Structure of a Java class 24 ■ Structure and components of a Java source code file 32 1.2 Executable Java applications 36 Ex

Trang 1

M A N N I N G Mala Gupta

Trang 2

OCA Java SE 8 Programmer I Certification Guide

Trang 4

OCA Java SE 8

Programmer I Certification Guide

M A N N I N GSHELTER 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 761

Shelter Island, NY 11964

Email: orders@manning.com

©2017 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 development editor: Francesco Bianchi

Shelter Island, NY 11964 Proofreader: Katie Tennant

Technical proofreader: Jean-François Morin

Typesetter: Dennis DalinnikCover designer: Marija Tudor

ISBN: 9781617293252

Printed in the United States of America

1 2 3 4 5 6 7 8 9 10 – EBM – 21 20 19 18 17 16

Trang 6

To Dheeraj, my pillar of strength

Trang 8

brief contents

Introduction 1

2 ■ Working with Java data types 92

4 ■ Selected classes from the Java API and arrays 221

Trang 10

contents

preface xvii

acknowledgments xix

about this book xxi

about the author xxix

about the cover illustration xxx

5 Next step: OCP Java SE 8 Programmer II (1Z0-809)

6 Complete exam objectives, mapped to book chapters, and readiness checklist 8

FAQs on exam preparation 10FAQs on taking the exam 18

8 The testing engine used in the exam 20

Trang 11

1.1 The structures of a Java class and a source code file 23

Structure of a Java class 24Structure and components of

a Java source code file 32

1.2 Executable Java applications 36

Executable Java classes versus non-executable Java classes 36 The main method 37Run a Java program from the command line 39

The need for packages 42Defining classes in a package using the package statement 42Using simple names with import statements 45Using packaged classes without using the import statement 47Importing a single member versus all members of a package 48The import statement doesn’t import the whole package tree 49Importing classes from the default package 50Static imports 50

1.4 Java access modifiers 51

Access modifiers 52Public access modifier 53Protected access modifier 54Default access (package access) 57 private access modifier 61Access modifiers and Java entities 62

1.5 Nonaccess modifiers 64

abstract modifier 65final modifier 66static modifier 67

1.6 Features and components of Java 72

Valid features and components of Java 72Irrelevant features and components of Java 74

1.10 Answers to sample exam questions 84

2.1 Primitive variables 93

Category: Boolean 95Category: signed numeric 96 Category: character (unsigned integer) 102Confusion with the names of the primitive data types 104

2.2 Identifiers 105

Valid and invalid identifiers 105

Trang 12

2.3 Object reference variables 106

What are object reference variables? 107Differentiating between object reference variables and primitive variables 109

Assignment operators 112Arithmetic operators 115 Relational operators 119Logical operators 121 Operator precedence 123

2.5 Wrapper classes 125

Class hierarchy of wrapper classes 125Creating objects of the wrapper classes 125Retrieving primitive values from the wrapper classes 126Parsing a string value to a

primitive type 127Difference between using the valueOf method and constructors of wrapper classes 128Comparing objects of wrapper classes 128Autoboxing and unboxing 130

2.9 Answers to sample exam questions 140

3.1 Scope of variables 149

Local variables 149Method parameters 151 Instance variables 152Class variables 153 Overlapping variable scopes 155

3.2 Object’s life cycle 158

An object is born 159Object is accessible 160 Object is inaccessible 161Garbage collection 163

3.3 Create methods with arguments and return values 166

Return type of a method 168Method parameters 169 Return statement 172

Argument list 175Return type 177Access level 177

3.5 Constructors of a class 178

User-defined constructors 178Default constructor 183 Overloaded constructors 185

3.6 Accessing object fields 188

What is an object field? 188Read and write object fields 189 Calling methods on objects 192

Trang 13

3.7 Apply encapsulation principles to a class 194

Need for encapsulation 195Apply encapsulation 195

3.8 Passing objects and primitives to methods 197

Passing primitives to methods 198Passing object references

to methods 199

3.12 Answers to sample exam questions 212

4.1 Welcome to the world of the String class 223

Creating String objects 223The class String is immutable 227 Methods of the class String 230String objects and

operators 235Determining equality of Strings 236

4.2 Mutable strings: StringBuilder 239

The StringBuilder class is mutable 239Creating StringBuilder objects 240Methods of class StringBuilder 241A quick note on the class StringBuffer 247

What is an array? 248Array declaration 249 Array allocation 250Array initialization 252 Combining array declaration, allocation, and initialization 254 Asymmetrical multidimensional arrays 255Arrays of type interface, abstract class, and class Object 256Members of

an array 258

Creating an ArrayList 259Adding elements to an ArrayList 261Accessing elements of an ArrayList 263 Modifying the elements of an ArrayList 265Deleting the elements of an ArrayList 266Other methods of ArrayList 267

4.5 Comparing objects for equality 273

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

4.6 Working with calendar data 278

LocalDate 279LocalTime 282LocalDateTime 285 Period 286DateTimeFormatter 291

Trang 14

4.10 Answers to sample exam questions 313

5.1 The if, if-else, and ternary constructs 324

The if construct and its flavors 324Missing else blocks 328 Implications of the presence and absence of {} in if-else

constructs 328Appropriate versus inappropriate expressions passed as arguments to an if statement 331Nested if constructs 332Ternary construct 334

5.2 The switch statement 338

Create and use a switch statement 339Comparing a switch statement with multiple if-else constructs 339Arguments passed to a switch statement 341Values passed to the label case of a switch statement 343Use of break statements within

a switch statement 345

Initialization block 348Termination condition 349 The update clause 349Optional parts of a for statement 350 Nested for loop 351

Iteration with enhanced for loop 352Limitations of the enhanced for loop 355Nested enhanced for loop 356

5.5 The while and do-while loops 358

The while loop 358The do-while loop 360 while and do-while block, expression, and nesting rules 362

Comparing do-while and while loops 362Comparing for and enhanced for loops 363Comparing for and while loops 364

5.7 Loop statements: break and continue 364

The break statement 364The continue statement 366 Labeled statements 367

5.11 Answers to sample exam questions 377

Trang 15

6.1 Inheritance with classes 385

The need to inherit classes 385Benefits 387A derived class contains within it an object of its base class 390Which base class members are inherited by a derived class? 391Which base class members aren’t inherited by a derived class? 391Derived classes can define additional properties and behaviors 391Abstract base class versus concrete base class 392

6.2 Use interfaces 394

Need for using interfaces 396Defining interfaces 398 Types of methods in an interface 401Implementing a single interface 405A class can’t extend multiple classes 407

A class can implement multiple interfaces 408Extending interfaces 411Modifying existing methods of an interface 414 Properties of members of an interface 417

6.3 Reference variable and object types 418

Using a variable of the derived class to access its own object 418 Using a variable of a superclass to access an object of a derived class 419Using a variable of an implemented interface to access

a derived class object 420The need for accessing an object using the variables of its base class or implemented interfaces 421

How to cast a variable to another type 424 Need for casting 426

6.5 Use this and super to access objects and constructors 427

Object reference: this 427Object reference: super 430

Polymorphism with classes 434Binding of variables and methods at compile time and runtime 439Polymorphism with interfaces 441

Comparing passing values with passing code to methods 446 Syntax of lambda expressions 449Interface Predicate 450

6.11 Answers to sample exam questions 461

Trang 16

7.2 Categories of exceptions 475

Identifying exception categories 476Class hierarchy of exception classes 476Checked exceptions 477 Runtime exceptions 478Errors 478

7.3 Creating a method that throws an exception 479

Create a method that throws a checked exception 480 Handle-or-declare rule 481Creating a method that throws runtime exceptions or errors 481A method can declare to throw all types of exceptions, even if it doesn’t 482

7.4 What happens when an exception is thrown? 483

Creating try-catch-finally blocks 485Using a method that throws

a checked exception 490Using a method that throws a runtime exception 491Using a method that throws an error 493 Will a finally block execute even if the catch block defines a return statement? 493What happens if both a catch and a finally block define return statements? 494What happens if a finally block modifies the value returned from a catch block? 495Can a try block be followed only by a finally block? 496Does the order of the exceptions caught in the catch blocks matter? 497Can I rethrow

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

to throw a checked exception instead of handling it? 500I can create nested loops, so can I create nested try-catch blocks too? 500 Should I handle errors? 502

7.5 Common exception classes and categories 503

ArrayIndexOutOfBoundsException and IndexOutOfBoundsException 504ClassCastException 505 IllegalArgumentException 507NullPointerException 508 ArithmeticException 511NumberFormatException 514 ExceptionInInitializerError 516StackOverflowError 518 NoClassDefFoundError 519OutOfMemoryError 519

7.9 Answers to sample exam questions 530

Trang 17

8.2 Answers to mock exam questions 574

appendix Answers to Twist in the Tale exercises 641

Trang 18

preface

Java programmer certifications are designed to tell would-be employers whether youreally know your stuff, and cracking the OCA Java SE 8 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-out, and youneed to understand the certification process so that you’re ready for the challengingquestions you’ll face in the exam

This book is a comprehensive guide to the 1Z0-808 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 reinforcekey concepts and prepare you for what you’ll see in the real exam, along with numeroustips, 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 common mistakes people make when taking theexam, and guides you in avoiding traps and pitfalls It provides

impor-■ Complete 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 19

■ 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 and prepare you well for the exam and that youwill pass it with flying colors!

Trang 20

acknowledgments

First and foremost, I thank Dheeraj—my pillar of strength, my best friend, and myhusband His constant guidance, encouragement, and love kept me going He helped

me to get started with this book and got me over the goal line

My sincere gratitude goes to Marjan Bace, publisher at Manning, for giving me theopportunity to author this book The Manning team has been wonderful—MichaelStephens ensured that it was worth it for Manning to have a book on this subject.Cynthia Kane, my development editor, is like sunshine Not only did she help me withthe organization of individual chapters and the overall book, but she pulled me throughwhenever the task of writing a book became overwhelming It’s always a pleasure towork with her Copyeditor Linda Recktenwald not only applied her magic to sentenceand language constructions but also supplemented her editing with valuable sugges-tions on technical content

Technical development editor Francesco Bianchi suggested multiple additions andmodifications, improving the content of this book Technical proofreader Jean-FrançoisMorin was outstanding in his review He not only pointed out existing errors but alsosuggested multiple improvements to the organization of the contents ProofreaderKatie Tennant was extremely capable and talented She reviewed the final manuscriptwith great precision

The technical reviewers on this book did an awesome job of reviewing the tents and sharing their valuable feedback and comments: Andrea Barisone, AndreaConsentino, Anutosh Ghosh, David Blau, Marty Henderson, Mirsad Vojnikovic, NicolaPedot, Sanjiv Kumar, Simona Russo, Travis Nelson, and Ursin Stauss I would also like

Trang 21

to thank Nicole Butterfield and Donna Clements, review editors, for managing thewhole review process and meticulously funneling the feedback to make this book better Dennis Dalinnik did an outstanding job of converting the black-and-white hand-drawn illustrations into glorious images It was amazing to scrutinize the page proofs

I also thank Dennis for adjusting the images in the final page proofs, which was a lot

of work Janet Vail and Mary Piergies were awesome in their expertise at turning alltext, code, and images into publishable form I am also grateful to Candace Gillhoolleyfor her efforts in promoting the book

I thank the MEAP readers for buying the book while it was being developed andfor their suggestions, corrections, and encouragement

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 daughters, Shreya and Pavni, who often advised me on the images that

I created for the book I thank my family for their unconditional support The bookwould have been not been possible without their love and encouragement

Trang 22

about this book

This book is written for developers with a working knowledge of Java who want to earnthe OCA Java SE 8 Programmer Certification It uses powerful tools and features tomake reaching your goal of certification a quick, smooth, and enjoyable experience.This section explains the features used in the book and tells you how to use the book

to get the most out of it as you prepare for the certification exam More information

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 developed a chapter-based exam objective map, as shown in figure 1.The full version is in the Introduction (table I.3)

section

1 3 o i c e s

e l b i a v o p c e

a l c a v a J a f o r u t c u r s

1.3 Create executable Java applications with a main method; run a Java program from Section 1.2

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 23

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

in table I.3 in the Introduction)

Exam objectives covered in this chapter What you need to know

[1.2] Define the structure of a Java class Structure of a Java class, with its components:

package and import statements, class tions, comments, variables, and methods

declara-Difference between the components of a Java class and that of a Java source code file.

[1.3] Create executable Java applications with a

main method; run a Java program from the

command line; including console output.

The right method signature for the main method

to create an executable Java application

The arguments that are passed to the main method.

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

Collec-in the OCP Java SE 8 Programmer II exam (exam number 1Z0-809) One of the reasons

[9.4] Declare and use an ArrayList of a given type

Trang 24

Exam tips

Each chapter provides multiple exam tips to reemphasize 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

Notes

All chapters also include multiple notes that draw your attention to points that should

be noted while you’re preparing for the exam Figure 5 shows an example

Sidebars

Sidebars contain information that may not be directly relevant to the exam but that isrelated to it Figure 6 shows an example

EXAM TIP An ArrayList preserves the order of insertion of its elements

Iterator, ListIterator, and the enhanced for loop will return the ments in the order in which they were added to the ArrayList An iterator(Iterator or ListIterator) lets you remove elements as you iterate an

ele-ArrayList It’s not possible to remove elements from an ArrayList whileiterating it using a for loop

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

NOTE Although the terms method parameters and method arguments are not the

same, you may have noticed that many programmers use them

interchange-ably Method parameters are the variables that appear in the definition of a method Method arguments are the actual values that are passed to a method

while executing it In figure 3.15, the variables phNum and msg are methodparameters If you execute this method as sendMsg("123456", "Hello"),then the String values "123456" and "Hello" are method arguments As youknow, you can pass literal values or variables to a method Thus, method argu-ments can be literal values or variables

Figure 5 Example note

static classes and interfaces

Certification aspirants frequently ask questions about static classes and faces, so I’ll quickly cover these in this section to ward off any confusion related tothem But note that static classes and interfaces are types of nested classes andinterfaces that aren’t covered by the OCA Java 8 Programmer I exam

inter-You can’t prefix the definition of a top-level class or an interface with the keyword

static A top-level class or interface is one that isn’t defined within another class orinterface The following code will fail to compile:

static class Person {}

Trang 25

Images

I use a lot of images in the chapters for an immersive learning experience I believethat a simple image can help you understand a concept quickly, and a little humor canhelp you to retain information longer

Simple images are used to draw your attention to a particular line of code (as shown

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

multiStrArr

null

0 1 2 0 1

0 1

2

A B

Jan Feb Mar 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 block always executes

Trang 26

I also use images to group and represent information for quick reference Figure 10shows an example of the protected members that can be accessed by derived or unre-lated classes in the same or separate packages I strongly recommend that you try tocreate a few of your own figures like these

An image can also add more meaning to a sequence of steps explained in the text Forexample, figure 11 seems to bring the Java compiler to life by allowing it to talk withyou and convey what it does when it gets to compile a class that doesn’t define a con-structor Again, try a few of your own! It’ll be fun!

The exam requires that you know multiple methods from classes such as String,

StringBuilder, ArrayList, and others The number of these methods can be 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

int age;

Employee() { super();

} }

Poor class Employee doesn’t have a constructor.

Let me create one for it.

Default constructor

Java compiler In

Out

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

compiler when it compiles a class without a constructor

String methods

Query position of chars

substring indexOf

Trang 27

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 try to usemodified code from the examples already covered in a chapter, and the “Twist in theTale” title refers to modified or tweaked code These exercises highlight how even

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

Value of a will increment after

this current value is used.

Because 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

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 lines 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.

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

nonlinear execution of code

Trang 28

small code modifications can change the behavior of your code They should age you to carefully examine all the code in the exam

My main reason for including these exercises is that on the real exam, you may get

to answer more than one question that seems to define exactly the same question andanswer options But on closer inspection, you’ll realize that these questions differslightly and that these differences change the behavior of the code and the correctanswer option

The answers to all the Twist in the Tale exercises are given in the appendix

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 or 11 exam questions These follow thesame pattern as the real exam questions Attempt these exam questions after com-pleting a chapter

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 8 Programmer I Certification Guide includes free access to a

private forum run by Manning Publications where you can make comments about thebook, ask technical questions, and receive help from the author and other users Youcan access and subscribe to the forum at www.manning.com/books/oca-java-se-8-programmer-i-certification-guide This page provides information on how to get onthe forum once you’re registered, what kind of help is available, and the rules of con-duct in the forum

Trang 29

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 theauthor, 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

NOTE This book uses code styles that you are likely to see on the exam Itoften includes practices that aren’t recommended on real projects, likepoorly indented code or skipping values for brevity, among others, but this isnot meant to encourage you to use obscure coding practices

Trang 30

about the author

Mala is passionate about making people employable by ing the gap between their existing and required skills In herquest to fulfill this mission, she is authoring books to help ITprofessionals and students succeed on industry-recognizedOracle Java certifications

She has master’s degrees in computer applications alongwith multiple other certifications from Oracle With over 15years of experience in IT as a developer, architect, trainer, andmentor, she has worked with international training and soft-ware services organizations on various Java projects She isexperienced in mentoring teams on technical and software development processes She is the founder and lead mentor of a portal (www.ejavaguru.com) that hasoffered Java courses for Oracle certification since 2006

Mala is a firm believer in creativity as an essential life skill To popularize theimportance of creativity, innovation, and design in life, she and her daughter startedKaagZevar (www.KaagZevar.com)—a platform for nurturing these values

Trang 31

about the cover illustration

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

“Morning Habit of a Lady of Quality in Barbary—1700.” The illustration is taken from

Thomas Jefferys’ A Collection of the Dresses of Different Nations, Ancient and Modern (four volumes), London, published between 1757 and 1772 The title page states that these are hand-colored copperplate engravings, heightened with gum arabic Thomas Jefferys (1719–1771) was called “Geographer to King George III.” He was an English cartogra- pher who was the leading map supplier of his day He engraved and printed maps for government and other official bodies and produced a wide range of commercial maps and atlases, especially of North America His work as a mapmaker sparked an interest

in local dress customs of the lands he surveyed and mapped, which are brilliantly

dis-played in this collection

Fascination with faraway lands and travel for pleasure were relatively new ena in the late 18th century, and collections such as this one were popular, introducingboth the tourist as well as the armchair traveler to the inhabitants of other countries.The diversity of the drawings in Jefferys’ volumes speaks vividly of the uniqueness andindividuality of the world’s nations some 200 years ago Dress codes have changed sincethen and the diversity by region and country, so rich at the time, has faded away It’s nowhard to tell apart the inhabitants of different continents, let alone different towns orregions Perhaps we have traded cultural diversity for a more varied personal life—cer-tainly for a more varied and fast-paced technological life

At a time when it is hard to tell one computer book from another, Manning celebratesthe inventiveness and initiative of the computer business with book covers based on therich diversity of regional life of two centuries ago, brought back to life by Jefferys’ pictures

Trang 32

Introduction

This book is intended specifically for individuals who wish to earn the OCA Java SE

8 Programmer I Certification (exam number 1Z0-808) It assumes that you arefamiliar with Java and have some experience working with it If you’re completelynew to the Java programming language, I suggest that you start your journey with

an entry-level book and then come back to this one

This introduction covers

■ Introduction to the Oracle Certified Associate (OCA) Java SE

8 Programmer I Certification (exam number 1Z0-808)

■ Importance of the OCA Java SE 8 Programmer certification

■ Comparison of the OCA Java SE 8 Programmer I exam to the

OCA Java SE 7 Programmer I exam

■ Comparison of the OCA Java SE 8 Programmer I exam

(1Z0-808) to the OCP Java SE 8 Programmer II exam (1Z0-809)

■ Detailed exam objectives, mapped to book chapters

■ FAQs on exam preparation and on taking the exam

■ Introduction to the testing engine used for the exam

Trang 33

2 Introduction

The information in this chapter is sourced from Oracle.com, public websites, and userforums Input has been taken from real people who have earned Java certification,including the author All efforts have been made to maintain the accuracy of the con-tent, but the details of the exam—including the exam objectives, pricing, exam passscore, total number of questions, maximum exam duration, and others—are subject

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

The Oracle Certified Associate (OCA) Java SE 8 Programmer I exam (1Z0-808) covers thefundamentals of Java SE 8 programming, such as the structure of classes and interfaces,variables of different data types, methods, operators, arrays, decision constructs, andloops The exam includes handling exceptions and a few commonly used classes from theJava API like String, StringBuilder, and ArrayList This exam doesn’t include a lot ofJava 8–specific language features It includes an introduction to functional-style program-ming with lambda expressions It partially covers the new Date and Time API

This exam is one of two steps to earning the title of Oracle Certified Professional(OCP) Java SE 8 Programmer It certifies that an individual possesses a strong founda-tion in the Java programming language Table 1 lists the details of this exam

The OCA Java SE 8 Programmer I exam (1Z0-808) is an entry-level exam in your Javacertification roadmap, as shown in figure 1

This exam is one of two steps to earn the title of OCP Java SE 8 Programmer Thedashed lines and arrows in figure 1 depict the prerequisites for certification OCP JavaProgrammer certification (any Java version) is a prerequisite to earn most of the otherhigher-level certifications in Java

Table 1 Details for the OCA Java SE 8 Programmer I exam (1Z0-808)

Trang 34

The importance of OCA Java SE 8 Programmer I Certification

To earn the OCP Java SE 8 Programmer title, you must pass the following two tions (in any order):

certifica-■ OCA Java SE 8 Programmer I (1Z0-808)

■ OCP Java SE 8 Programmer II (1Z0-809)

NOTE At the time of writing, Oracle made this exam a prerequisite for ing the 1Z0-809 exam Earlier, Oracle allowed passing the 1Z0-808 and 1Z0-809exams in any order Even when this exam wasn’t a prerequisite for passing the

Java SE 7 Java SE 7

Java SE 5/6

Java SE 6 Developer

Java EE 6 Enterprise Architect

Java SE

Java EE

Java SE 5/6

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 EE 6 JavaServer Faces Developer

Increasing difficulty level

Trang 35

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

■ OCA Java SE 8 Programmer I (exam number: 1Z0-808)

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

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

Table 2 compares these exams on their target audience, Java version, question count,duration, and passing score

The OCA Java SE 8 Programmer I Certification adds the following topics to the onescovered by the OCA Java SE 7 Programmer I Certification:

■ Features and components of Java

■ Wrapper classes

■ Ternary constructs

■ Some classes from the new Java 8 Date and Time API

■ Creating and using lambda expressions

■ Predicate interface

Table 2 Comparing exams: OCA Java SE 8 Programmer I, OCA Java SE 7 Programmer I, and OCA Java

SE 5/6

OCA Java SE 8 Programmer I (1Z0-803)

OCA Java SE 7 Programmer I (1Z0-803)

OCA Java SE 5/SE 6 (1Z0-850)

Target audience Java programmers Java programmers Java programmers and IT

Trang 36

Comparing OCA Java exam versions

Figure 2 shows a detailed comparison of the exam objectives of the OCA Java SE 8 andOCA Java SE 7 Programmer I exams Here’s the legend to understand it:

Light gray background—Main exam objective.

Yellow background—Covered only in the OCA Java SE 8 exam.

Green background—Although the text or main exam objective of this

subobjec-tive differs, it is covered by the other exam

Use Java operators, including

parentheses to override operator

precedence

Ternary constructs

Manipulate data using the StringBuilder class and its methods

Creating and manipulating Strings

Use Java operators Use parenthesis to override operator precedence

Create methods with arguments and return values Create an overloaded method Differentiate between default and user defined constructors Create and overload constructors

Develop code that uses wrapper

classes such as Boolean Double , ,

and Integer

Java basics

Define the scope of variables Define the structure of a Java class Create executable Java applications with Import other Java packages to make them accessible in your code

Declare and initialize variables (including casting of primitive data types) Differentiate between object reference variables and primitive variables Know how to read or write to object fields Explain an object s lifecycle ’

Test equality between Strings and other objects using == and equals() Create if and if/else and ternary Use a switch statement

Declare, instantiate, initialize and use

a one-dimensional array Declare, instantiate, initialize and use a multi-dimensional array

Create and use while loops Create and use for loops, including the enhanced for loop

Create and use do while / loops Compare loop constructs Use break and continue

Apply the static keyword to methods and fields

Apply access modifiers Apply encapsulation principles to a class

Determine the effect upon object references and primitive values when they are passed into methods that change the values

Create methods with arguments

and return values; including

overloaded methods

Create and overload constructors;

including impact on default

constructors

Declare and use an ArrayList

Run a Java program from the command

line; including console output

Compare and contrast the features and

components of Java, such as platform

independence, object orientation,

encapsulation, and so on

Objectives common to both exams

Working with Java data types

OCA Java SE 7 OCA Java SE 8

Using operators and decision constructs

Creating and using arrays

Using loop constructs

Working with methods and encapsulation

a main method

constructs

Figure 2 Comparing exam objectives of the OCA Java SE 8 Programmer I and OCA Java SE 7 Programmer I

Trang 37

6 Introduction

Figure 3 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 areexclusive to each of these exam versions and those that are common to both The firstcolumn shows the objectives that are included only in OCA Java SE 5/6 (1Z0-850), themiddle column shows common exam objectives, and the right column shows examobjectives covered only in OCA Java SE 7 Programmer I (1Z0-803)

Determine when casting is necessary Use super and this to access objects and constructors

Use abstract classes and interfaces

Differentiate among checked exceptions, unchecked exceptions, and errors Create a try catch - block and determine how exceptions alter normal program flow

Manipulate data using the

StringBuilder class and its methods

Creating and manipulating Strings

Create and manipulate calendar data

using classes from

Write a simple lambda expression that

consumes a lambda predicate expression

Describe the advantages of exception

Describe inheritance and its benefits

Develop code that demonstrates the use

of polymorphism; including overriding

and object type versus reference type

Implement inheritance Develop code that demonstrates the use of polymorphism Differentiate between the type

of a reference and the type of

Working with Inheritance

Handling exceptions

Working with selected classes from the Java API

Figure 2 Comparing exam objectives of the OCA Java SE 8 Programmer I and OCA Java SE 7 Programmer I

certifications (continued)

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 3 Comparing objectives of exams OCA Java SE 5/6 and OCA Java SE 7 Programmer I

Trang 39

8 Introduction

After successfully passing the OCA Java SE 8 Programmer I exam, the next step is totake the OCP Java SE 8 Programmer II exam The OCP Java SE 8 Programmer II certi-fication is designed for individuals who possess advanced skills in the Java program-ming language It covers advanced Java features such as threads, concurrency,collections, the Streams API, Java file I/O, inner classes, localization, and others

and readiness checklist

Table 3 includes a complete list of exam objectives for the OCA Java SE 8 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

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

Exam objectives Covered in chapter/

section

1.3 Create executable Java applications with a main method; run a Java program from

the command line, including console output

Section 1.2

1.4 Import other Java packages to make them accessible in your code Section 1.3

1.5 Compare and contrast the features and components of Java, such as platform

inde-pendence, object orientation, encapsulation, and so on

Section 1.6

2.1 Declare and initialize variables (including casting of primitive data types) 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 lifecycle (creation, "dereference by reassignment," and garbage

collection)

Section 3.2

2.5 Develop code that uses wrapper classes such as Boolean , Double , and Integer Section 2.5

3.1 Use Java operators, including parentheses to override operator precedence Section 2.4

3.2 Test equality between Strings and other objects using == and equals() Sections 4.1 and 4.5 3.3 Create if and if / else and ternary constructs Section 5.1

4.1 Declare, instantiate, initialize, and use a one-dimensional array Section 4.3

4.2 Declare, instantiate, initialize, and use a multidimensional array Section 4.3

Trang 40

Complete exam objectives, mapped to book chapters, and readiness checklist

5.2 Create and use for loops, including the enhanced for loop Sections 5.3 and 5.4

5.5 Use break and continue Section 5.7

6.1 Create methods with arguments and return values, including overloaded methods Sections 3.3 and 3.4 6.2 Apply the static keyword to methods and fields Section 1.5

6.3 Create and overload constructors, including impact on default constructors Section 3.5

6.6 Determine the effect on object references and primitive values when they are passed

into methods that change the values

Section 3.8

7.2 Develop code that demonstrates the use of polymorphism, including overriding and

object type versus reference type

Sections 6.3 and 6.6

7.4 Use super and this to access objects and constructors Section 6.5

7.5 Use abstract classes and interfaces Sections 1.5, 6.1, 6.2,

and 6.6

8.1 Differentiate among checked exceptions, unchecked exceptions, and errors Section 7.2

8.2 Create a try - catch block and determine how exceptions alter normal program flow Section 7.4

8.3 Describe the advantages of exception handling Section 7.1

8.4 Create and invoke a method that throws an exception Sections 7.3 and 7.4 8.5 Recognize common exception classes (such as NullPointerException ,

ArithmeticException , ArrayIndexOutOfBoundsException , ClassCastException )

Section 7.5

9 Working with selected classes from the Java API Chapters 4 and 6 9.1 Manipulate data using the StringBuilder class and its methods Section 4.2

9.3 Create and manipulate calendar data using classes from

java.time.Local-DateTime , java.time.LocalDate , java.time.LocalTime ,

java.time.format.DateTimeFormatter , and java.time.Period

Section 4.6

9.4 Declare and use an ArrayList of a given type Section 4.4

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

Exam objectives Covered in chapter/

section

Ngày đăng: 12/05/2017, 14:48

TỪ KHÓA LIÊN QUAN

TRÍCH ĐOẠN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN