OCA Java SE 8 Programmer I Certification Guide
Mala Gupta
  • September 2016
  • ISBN 9781617293252
  • 704 pages
  • printed in black & white

Guides you through all the tricks and pitfalls you need to master in order to pass the exam.

Jean-François Morin, Laval University

OCA Java SE 8 Programmer I Certification Guide prepares you for the 1Z0-808 with complete coverage of the exam. You'll explore important Java topics as you systematically learn what's required to successfully pass the test.

Table of Contents detailed table of contents

Introduction

1. Java basics

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

1.1.1. Structure of a Java class

1.1.2. Structure and components of a Java source code file

1.2. Executable Java applications

1.2.1. Executable Java classes versus nonexecutable Java classes

1.2.2. The main method

1.2.3. Run Java program from command line

1.3. Java packages

1.3.1. The need for packages

1.3.2. Defining classes in a package using the package statement

1.3.3. Using simple names with import statements

1.3.4. Using packaged classes without using the import statement

1.3.5. Importing a single member versus all members of a package

1.3.6. The import statement doesn't import the whole package tree

1.3.7. Importing classes from the default package

1.3.8. Static imports

1.4. Java access modifiers

1.4.1. Access modifiers

1.4.2. Public access modifier

1.4.3. Protected access modifier

1.4.4. Default access (package access)

1.4.5. Private access modifier

1.4.6. Access modifiers and Java entities

1.5. Nonaccess modifiers

1.5.1. Abstract modifier

1.5.2. Final modifier

1.5.3. Static modifier

1.6. Features and components of Java

1.6.1. Valid features and components of Java

1.6.2. Irrelevant features and components of Java

1.7. Summary

1.8. Review notes

1.9. Sample exam questions

1.10. Answers to sample exam questions

2. Working with Java data types

2.1. Primitive variables

2.1.1. Category: Boolean

2.1.2. Category: Numeric

2.1.3. Category: Character

2.1.4. Confusion with the names of the primitive data types

2.2. Identifiers

2.2.1. Valid and invalid identifiers

2.3. Object reference variables

2.3.1. What are object reference variables?

2.3.2. Differentiating between object reference variables and primitive variables

2.4. Operators

2.4.1. Assignment operators

2.4.2. Arithmetic operators

2.4.3. Relational operators

2.4.4. Logical operators

2.4.5. Operator precedence

2.5. Wrapper classes

2.5.1. Class hierarchy of wrapper classes

2.5.2. Creating objects of the wrapper classes

2.5.3. Retrieving primitive values from the wrapper classes

2.5.4. Parsing a string value to a primitive type

2.5.5. Difference between using the valueOf method and constructors of wrapper classes

2.5.6. Comparing objects of wrapper classes

2.5.7. Autoboxing and Unboxing

2.6. Summary

2.7. Review notes

2.8. Sample exam questions

2.9. Answers to sample exam questions

3. Methods and encapsulation

3.1. Scope of variables

3.1.1. Local variables

3.1.2. Method parameters

3.1.3. Instance variables

3.1.4. Class variables

3.1.5. Overlapping variable scopes

3.2. Object's life cycle

3.2.1. An object is born

3.2.2. Object is accessible

3.2.3. Object is inaccessible

3.2.4. Garbage collection

3.3. Create methods with arguments and return values

3.3.1. Return type of a method

3.3.2. Method parameters

3.3.3. Return statement

3.4. Create an overloaded method

3.4.1. Argument list

3.4.2. Return type

3.4.3. Access modifier

3.5. Constructors of a class

3.5.1. User-defined constructors

3.5.2. Default constructor

3.5.3. Overloaded constructors

3.6. Accessing object fields

3.6.1. What is an object field?

3.6.2. Read and write object fields

3.6.3. Calling methods on objects

3.7. Apply encapsulation principles to a class

3.7.1. Need for encapsulation

3.7.2. Apply encapsulation

3.8. Passing objects and primitives to methods

3.8.1. Passing primitives to methods

3.8.2. Passing object references to methods

3.9. Summary

3.10. Review notes

3.11. Sample exam questions

3.12. Answers to sample exam questions

4. Selected classes from the Java API and arrays

4.1. Welcome to the world of the String class

4.1.1. Creating String objects

4.1.2. The class String is immutable

4.1.3. Methods of the class String

4.1.4. String objects and operators

4.1.5. Determining equality of Strings

4.2. Mutable strings: StringBuilder

4.2.1. The StringBuilder class is mutable

4.2.2. Creating StringBuilder objects

4.2.3. Methods of class StringBuilder

4.2.4. A quick note on the class StringBuffer

4.3. Arrays

4.3.1. What is an array?

4.3.2. Array declaration

4.3.3. Array allocation

4.3.4. Array initialization

4.3.5. Combining array declaration, allocation, and initialization

4.3.6. Asymmetrical multidimensional arrays

4.3.7. Arrays of type interface, abstract class, and class Object

4.3.8. Members of an array

4.4. ArrayList

4.4.1. Creating an ArrayList

4.4.2. Adding elements to an ArrayList

4.4.3. Accessing elements of an ArrayList

4.4.4. Modifying the elements of an ArrayList

4.4.5. Deleting the elements of an ArrayList

4.4.6. Other methods of ArrayList

4.5. Comparing objects for equality

4.5.1. The method equals in the class java.lang.Object

4.5.2. Comparing objects of a user-defined class

4.5.3. Incorrect method signature of the equals method

4.5.4. Contract of the equals method

4.6. Working with calendar data

4.6.1. LocalDate

4.6.2. LocalTime

4.6.3. LocalDateTime

4.6.4. Period

4.6.5. DateTimeFormatter

4.7. Summary

4.8. Review notes

4.9. Sample exam questions

4.10. Answers to sample exam questions

5. Flow control

5.1. The if, if-else and ternary constructs

5.1.1. The if construct and its flavors

5.1.2. Missing else blocks

5.1.3. Implications of the presence and absence of {} in if-else constructs

5.1.4. Appropriate versus inappropriate expressions passed as arguments to an if statement

5.1.5. Nested if constructs

5.1.6. Ternary construct

5.2. The switch statement

5.2.1. Create and use a switch statement

5.2.2. Comparing a switch statement with multiple if-else constructs

5.2.3. Arguments passed to a switch statement

5.2.4. Values passed to the label case of a switch statement

5.2.5. Use of break statements within a switch statement

5.3. The for loop

5.3.1. Initialization block

5.3.2. #B Variable ctr isn't accessible outside for loopTermination condition

5.3.3. The update clause

5.3.4. Optional parts of a for statement

5.3.5. Nested for loop

5.4. The enhanced for loop

5.4.1. Iteration with enhanced for loop

5.4.2. Limitations of the enhanced for loop

5.4.3. Nested enhanced for loop

5.5. The while and do-while loops

5.5.1. The while loop

5.5.2. The do-while loop

5.5.3. While and do-while block, expression, and nesting rules

5.6. Comparing loop constructs

5.6.1. Comparing do-while and while loops

5.6.2. Comparing for and enhanced for loops

5.6.3. Comparing for and while loops

5.7. Loop statements: break and continue

5.7.1. The break statement

5.7.2. The continue statement

5.7.3. Labeled statements

5.8. Summary

5.9. Review notes

5.10. Sample exam questions

5.11. Answers to sample exam questions

6. Working with inheritance

6.1. Inheritance with classes

6.1.1. Need to inherit classes

6.1.2. Benefits

6.1.3. A derived class contains within it an object of its base class

6.1.4. Which base class members are inherited by a derived class?

6.1.5. Which base class members aren't inherited by a derived class?

6.1.6. Derived classes can define additional properties and behaviors

6.1.7. Abstract base class versus concrete base class

6.2. Use interfaces

6.2.1. Need of using interfaces

6.2.2. Defining interfaces

6.2.3. Types of methods in an interface

6.2.4. Implementing a single interface

6.2.5. A class can't extend multiple classes

6.2.6. A class can implement multiple interfaces

6.2.7. Extending interfaces

6.2.8. Modifying existing methods of an interface

6.2.9. Properties of members of an interface

6.3. Reference variable and object types

6.3.1. Using a variable of the derived class to access its own object

6.3.2. Using a variable of a superclass to access an object of a derived class

6.3.3. Using a variable of an implemented interface to access a derived class object

6.3.4. The need for accessing an object using the variables of its base class or implemented interfaces

6.4. Casting

6.4.1. How to cast a variable to another type

6.4.2. Need for casting

6.5. Use this and super to access objects and constructors

6.5.1. Object reference: this

6.5.2. Object reference: super

6.6. Polymorphism

6.6.1. Polymorphism with classes

6.6.2. Binding of variables and methods at compile time and runtime

6.6.3. Polymorphism with interfaces

6.7. Simple Lambda expressions

6.7.1. Comparing passing values with passing code to methods

6.7.2. Syntax of Lambda expressions

6.7.3. Interface Predicate

6.8. Summary

6.9. Review notes

6.10. Sample exam questions

6.11. Answers to sample exam questions

7. Exception handling

7.1. Exceptions in Java

7.1.1. A taste of exceptions

7.1.2. Why handle exceptions separately?

7.1.3. Do exceptions offer any other benefits?

7.2. Categories of exceptions

7.2.1. Identifying exception categories

7.2.2. Class hierarchy of exception classes

7.2.3. Checked exceptions

7.2.4. Runtime exceptions

7.2.5. Errors

7.3. Creating a method that throws exception

7.3.1. Create a method that throws checked exception

7.3.2. Handle-or-declare rule

7.3.3. Creating a method that throws runtime exceptions or errors

7.3.4. A method can declare to throw all types of exceptions, even if it doesn't

7.4. What happens when an exception is thrown?

7.4.1. Creating try-catch-finally blocks

7.4.2. Using a method that throws a checked exception

7.4.3. Using a method that throws runtime exception

7.4.4. Using a method that throws error

7.4.5. In the remainder of this section, we'll look at some frequently asked questions on try-catch-finally blocks that often overwhelm certification aspirants.Will a finally block execute even if the catch block defines a return statement?

7.4.6. What happens if both a catch and a finally block define return statements?

7.4.7. What happens if a finally block modifies the value returned from a catch block?

7.4.8. Can a try block be followed only by a finally block?

7.4.9. Does the order of the exceptions caught in the catch blocks matter?

7.4.10. Can I rethrow an exception or the error I catch?

7.4.11. Can I declare my methods to throw a checked exception, instead of handling it?

7.4.12. I can create nested loops, so can I create nested try-catch blocks too?

7.4.13. Should I handle errors?

7.5. Common exception classes and categories

7.5.1. ArrayIndexOutOfBoundsException and IndexOutOfBoundsException

7.5.2. ClassCastException

7.5.3. IllegalArgumentException

7.5.4. NullPointerException

7.5.5. ArithmeticException

7.5.6. NumberFormatException

7.5.7. ExceptionInInitializerError

7.5.8. StackOverflowError

7.5.9. NoClassDefFoundError

7.5.10. OutOfMemoryError

7.6. Summary

7.7. Review notes

7.8. Sample exam questions

7.9. Answers to sample exam questions

8. Full mock exam

8.1. Mock exam

8.2. Answers to mock exam questions

Appendixes

Appendix A: Answers to Twist in the Tale exercises

A.1. Chapter 1: Java basics

A.1.1. Twist in the Tale 1.1

A.1.2. Twist in the Tale 1.2

A.1.3. Twist in the Tale 1.3

A.1.4. Twist in the Tale 1.4

A.2. Chapter 2—Working with Java data types

A.2.1. Twist in the Tale 2.1 (part 1)

A.2.2. Twist in the Tale 2.1 (part 2)

A.3. Twist in the Tale 2.2

A.3.1. Twist in the Tale 2.3

A.3.2. Twist in the Tale 2.4

A.4. Chapter 3—Methods and encapsulation

A.4.1. Twist in the Tale 3.1

A.4.2. Twist in the Tale 3.2

A.4.3. Twist in the Tale 3.3

A.5. Chapter 4—String, StringBuilder, Arrays, and ArrayList

A.5.1. Twist in the Tale 4.1

A.5.2. Twist in the Tale 4.2

A.5.3. Twist in the Tale 4.3

A.5.4. Twist in the Tale 4.4

A.6. Chapter 5—Flow control

A.6.1. Twist in the Tale 5.1

A.6.2. Twist in the Tale 5.2

A.6.3. Twist in the Tale 5.3

A.6.4. Twist in the Tale 5.4

A.7. Chapter 6—Working with inheritance

A.7.1. Twist in the Tale 6.1

A.7.2. Twist in the Tale 6.2

A.7.3. Twist in the Tale 6.3

A.7.4. Twist in the Tale 6.4

A.8. Chapter 7—Exception handling

A.8.1. Twist in the Tale 7.1

A.8.2. Twist in the Tale 7.2

A.8.3. Twist in the Tale 7.3

A.8.4. Twist in the Tale 7.4

A.8.5. Twist in the Tale 7.5

About the book

To earn the OCA Java SE 8 Programmer I Certification, you have to know your Java inside and out, and to pass the exam you need to understand the test itself. This book cracks open the questions, exercises, and expectations you’ll face on the OCA exam so you’ll be ready and confident on test day.

OCA Java SE 8 Programmer I Certification Guide prepares Java developers for the 1Z0-808 with thorough coverage of Java topics typically found on the exam. Each chapter starts with a list of exam objectives mapped to section numbers, followed by sample questions and exercises that reinforce key concepts. You’ll learn techniques and concepts in multiple ways, including memorable analogies, diagrams, flowcharts, and lots of well-commented code. You’ll also get the scoop on common exam mistakes and ways to avoid traps and pitfalls.

What's inside

  • Covers all exam topics
  • Hands-on coding exercises
  • Flowcharts, UML diagrams, and other visual aids
  • How to avoid built-in traps and pitfalls
  • Complete coverage of the OCA Java SE 8 Programmer I exam (1Z0-808)

About the reader

Written for developers with a working knowledge of Java who want to earn the OCA Java SE 8 Programmer I Certification.

About the author

Mala Gupta is a Java coach and trainer who holds multiple Java certifications. Since 2006 she has been actively supporting Java certification as a path to career advancement.


Buy
combo $59,99 pBook + eBook
eBook $47,99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

Mala Gupta is a master of her art—she wrote the definitive guide to this exam!

Marty Henderson, Anthem Inc.

Offers a thorough and well-structured preparation for the OCA exam.

Ursin Strauss, Swiss Post

Clear, concise, correct, and complete.

Travis Nelson, Software Technology Group