List of Figures

Chapter Introduction

Figure 1. OCA Java SE 8 Programmer certification is an entry-level certification in the Java certification roadmap.

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

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

Figure 4. Exam question type 1

Figure 5. Exam question type 2

Figure 6. Exam question type 3

Figure 7. Exam question type 4

Figure 8. Exam question type 5

Figure 9. Exam question type 6

Figure 10. Exam question type 7

Figure 11. Exam question type 8

Chapter 1. Java basics

Figure 1.1. Relationship between the class file Person and the files Person.java and Person.class and how one transforms into another

Figure 1.2. Components of a Java class

Figure 1.3. UML representation of the relationship between class AnnualExam and ExamQuestion

Figure 1.4. Relationship between the packageless class AnnualExam and ExamQuestion

Figure 1.5. Components of a class declaration

Figure 1.6. Class LaunchApplication is an executable Java class, but the rest of the classes—Window, UserData, ServerConnection, and UserPreferences—aren't.

Figure 1.7. Ingredients of a correct main method

Figure 1.8. Using the command prompt to execute a Java application

Figure 1.9. Passing command parameters to a main method

Figure 1.10. Harry knows six Pauls!

Figure 1.11. A UML class diagram showing the relationship shared by package certification, class ExamQuestion, and interface MultipleChoice

Figure 1.12. A subpackage and its corresponding class definition

Figure 1.13. Matching directory structure and package hierarchy

Figure 1.14. There’s no constraint on the location of the base directory to define directories corresponding to package hierarchy.

Figure 1.15. To refer to each other’s members, Home and Office should specify that they exist in separate places.

Figure 1.16. LivingRoom can be accessed in Cubicle by using its fully qualified name. It can also be accessed using its simple name if you also use the import statement.

Figure 1.17. A UML representation of classes LivingRoom and Cubicle, defined in separate packages, with their associations

Figure 1.18. A UML representation of the certification package

Figure 1.19. A UML representation of package com.oracle.javacert and its subpackages

Figure 1.20. The nonpublic class Book can’t be accessed outside the package library.

Figure 1.21. A set of classes and their relationships to help you understand access modifiers

Figure 1.22. Understanding the public access modifier

Figure 1.23. Classes that can access a public class and its members

Figure 1.24. Understanding the protected access modifier

Figure 1.25. Access of protected members of the class Book in unrelated and derived classes, from the same and separate packages

Figure 1.26. Classes that can access protected members

Figure 1.27. Understanding class representation for default access

Figure 1.28. Access of members with default access to the class Book in unrelated and derived classes from the same and separate packages

Figure 1.29. This Superfast Burgers can’t be accessed from outside the island because the island is inaccessible by air and water.

Figure 1.30. The classes that can access members with default (package) access

Figure 1.31. Understanding the private access modifier

Figure 1.32. No classes can access private members of another class

Figure 1.33. Comparing a shared bank vault with a static variable

Figure 1.34. Definition of the class Emp with a static variable bankVault and non-static variable name

Chapter 2. Working with Java data types

Figure 2.1. Matching a value with its corresponding type

Figure 2.2. Categorization of primitive data types

Figure 2.3. Defining and assigning a primitive variable

Figure 2.4. Converting an integer from decimal to octal

Figure 2.5. Converting an integer from decimal to hexadecimal

Figure 2.6. Converting an integer from decimal to binary

Figure 2.7. Never use double quotes to assign a letter as a char value.

Figure 2.8. The output of assigning a character using the integer value 122 versus the Unicode value u0122

Figure 2.9. The output of assigning a negative value to a character variable

Figure 2.10. The creation and assignment of a reference variable

Figure 2.11. An object reference variable and the referenced object in memory

Figure 2.12. Dog leash analogy for understanding objects

Figure 2.13. Primitive variables store the actual values, whereas object reference variables store the addresses of the objects they refer to.

Figure 2.14. Differences between object reference variables and primitive variables

Figure 2.15. Assigning a bigger value (long) to a variable (int) that’s only capable of storing a smaller value range

Figure 2.16. Assigning a smaller value (int) to a variable (long) that’s capable of storing a larger value range

Figure 2.17. Evaluation of an expression that has multiple occurrences of unary operators in postfix and prefix notation

Figure 2.18. Hierarchy of wrapper classes

Figure 2.19. Autoboxing and unboxing

Chapter 3. Methods and encapsulation

Figure 3.1. You can access the local variable avg only within the method getAverage.

Figure 3.2. The scope of local variable avg is part of the if statement.

Figure 3.3. The scope of the method parameter val, which is defined in the method setTested

Figure 3.4. Comparison of the scope of method parameters and local variables

Figure 3.5. The instance variable tested is accessible across the object of class Phone.

Figure 3.6. The scope of the class variable softKeyboard is limited to the package com.mobile because it’s defined in the class Phone, which is defined with default access. The class variable softKeyboard is shared and accessible across all objects of the class Phone.

Figure 3.7. The scopes of variables can overlap.

Figure 3.8. Comparing the scope, or life span, of all four variables

Figure 3.9. The difference between declaring a reference variable and initializing a reference variable

Figure 3.10. Objects can be dereferenced by reassignment of variables.

Figure 3.11. Comparing object reference variables and objects to dog leashes and leashed and unleashed dogs

Figure 3.12. A group of instances with no external references forms an island of isolation, which is eligible for garbage collection.

Figure 3.13. Different types of methods

Figure 3.14. An example of a method that accepts method parameters and defines a return type and a return statement

Figure 3.15. An example of a method that accepts method parameters and defines a return type and a return statement

Figure 3.16. An example of a method that accepts method parameters and defines a return type and a return statement

Figure 3.17. Real-life examples of overloaded methods

Figure 3.18. The series of steps that may be executed when you create a new bank account. These steps can be compared with what a constructor does in Java.

Figure 3.19. A class, Employee, with a constructor defined by the user Paul

Figure 3.20. When the Java compiler compiles a class that doesn’t define a constructor, the compiler creates one for it.

Figure 3.21. When a class with a constructor is compiled, the Java compiler doesn’t add a default constructor to it.

Figure 3.22. Two objects of the class Employee

Figure 3.23. Objects of class Person, referred to by variables person1, person2, p1, and p2

Figure 3.24. The change in the objects referred to by variables during the execution of the method swap

Figure 3.25. Modification of the state of an object passed to the method resetValueOfMember-Variable

Chapter 4. Selected classes from the Java API and arrays

Figure 4.1. String objects created using the operator new always refer to separate objects, even if they store the same sequence of characters.

Figure 4.2. String objects created using the assignment operator (=) may refer to the same object if they store the same sequence of characters.

Figure 4.3. The sequence of steps that executes when Java is unable to locate a String in a pool of String objects

Figure 4.4. The sequence of actions that executes when Java locates a String in the pool of String objects

Figure 4.5. UML representations of the class String and a String object with String’s instance attribute value

Figure 4.6. Mapping characters stored by a String with the positions at which they’re stored

Figure 4.7. The partial definition of the method replace from the class String shows that this method creates and returns a new String object rather than modifies the value of the String object on which it’s called.

Figure 4.8. Categorization of the String methods

Figure 4.9. The sequence of characters of "Paul" stored by String and the corresponding array index positions

Figure 4.10. The characters "ABCAB" stored by String

Figure 4.11. The String "Oracle"

Figure 4.12. How the method substring looks for the specified characters from the start until the end position

Figure 4.13. The StringBuilder object with character values and their corresponding storage positions

Figure 4.14. Categorization of StringBuilder methods

Figure 4.15. Inserting a char using the method insert in StringBuilder

Figure 4.16. Inserting a substring of String in StringBuilder

Figure 4.17. The method delete(2,4) doesn’t delete the character at position 4.

Figure 4.18. Comparing the replace methods in String (left) and StringBuilder (right). The method replace in String accepts the characters to be replaced. The method replace in StringBuilder accepts a position to be replaced.

Figure 4.19. An array of int primitive data type and another of String objects

Figure 4.20. One-dimensional and multidimensional (two- and three-dimensional) arrays

Figure 4.21. Array declaration includes the array type and array variable

Figure 4.22. Square brackets can follow either the variable name or its type. In the case of multidimensional arrays, it can follow both of them.

Figure 4.23. Array declaration creates a variable that refers to null.

Figure 4.24. The difference in array allocation of a two-dimensional array when it’s allocated using values for only one of its dimensions and for both of its dimensions

Figure 4.25. An asymmetrical array

Figure 4.26. An array of class Object

Figure 4.27. Variable elementData shown within an object of ArrayList

Figure 4.28. Code that adds elements to the end of an ArrayList and at a specified position

Chapter 5. Flow control

Figure 5.1. Multiple flavors of the if statement: if, if-else, and if-else-if-else

Figure 5.2. Multiple flavors of if statements implemented in code

Figure 5.3. Execution of the if-else-if-else code

Figure 5.4. How to match if-else pairs for poorly indented code

Figure 5.5. Correct code indentation (with or without braces) makes the code more readable.

Figure 5.6. Comparing a ternary construct with an if-else construct

Figure 5.7. The if-else-if-else construct is like a series of questions and answers.

Figure 5.8. A switch statement is like asking a question and acting on the answer.

Figure 5.9. Types of arguments that can be passed to a switch statement and an if construct

Figure 5.10. Differences in code flow for a switch statement with and without break statements

Figure 5.11. The flow of control in a for loop

Figure 5.12. The flow of control in a for loop using a code example

Figure 5.13. Comparison of the hands of a clock to a nested loop

Figure 5.14. The array multiArr after its initialization

Figure 5.15. Pictorial representation of nestedArrayList

Figure 5.16. Comparison between a clock with three hands and the levels of a nested for loop

Figure 5.17. Nested for loop with the loop values for which each of these nested loops iterates

Figure 5.18. A flowchart depicting the flow of code in a while loop

Figure 5.19. Flowchart showing the flow of code in a do-while loop

Figure 5.20. Comparing do-while and while loops

Figure 5.21. The flow of control when the break statement executes within a loop

Figure 5.22. Comparing the flow of control when using break and continue statements in a loop

Chapter 6. Working with inheritance

Figure 6.1. Properties and behavior of a Programmer and a Manager, together with their representations as classes

Figure 6.2. Identify common properties and behaviors of a Programmer and a Manager, pull them out into a new position, and name it Employee.

Figure 6.3. The classes Programmer and Manager extend the class Employee.

Figure 6.4. Differences in the size of the classes Astronaut, Doctor, Programmer, and Manager, both with and without inheriting from the class Employee

Figure 6.5. Adding a new property, facebookId, to all classes, with and without the base class Employee

Figure 6.6. An object of a derived class can access features of its base class object.

Figure 6.7. You can compare an interface with a window that can connect multiple objects but has limited access to them.

Figure 6.8. Relationships among the classes Employee, Programmer, and Manager and the interfaces Trainable and Interviewer

Figure 6.9. Relationships among the classes Employee, Programmer, and Manager and the interfaces Trainable and Interviewer, with interfaces represented by circles

Figure 6.10. All the methods of an interface are implicitly public. Its variables are implicitly public, static, and final.

Figure 6.11. Components of an interface declaration

Figure 6.12. What happens if a class is allowed to extend multiple classes?

Figure 6.13. The interface MyInterface extends the interfaces BaseInterface1 and BaseInterface2.

Figure 6.14. Methods defined in an interface don’t have a method body.

Figure 6.15. What happens when you change a static method in an interface to a default or abstract method

Figure 6.16. What happens when you change an abstract method in an interface to a default or static method

Figure 6.17. What happens when you change a default method in an interface to an abstract or static method

Figure 6.18. A variable of type Employee can see only the members defined in the class Employee.

Figure 6.19. A variable of type Interviewer can see only the members defined in the interface Interviewer.

Figure 6.20. All types of Employees can attend an office party.

Figure 6.21. A reference variable of the interface Interviewer referring to an object of the class HRExecutive

Figure 6.22. The Java compiler doesn’t compile code if you try to access the variable specialization, defined in the class HRExecutive, by using a variable of the interface Interviewer.

Figure 6.23. Casting can be used to access the variable specialization, defined in the class HRExecutive, by using a variable of the interface Interviewer.

Figure 6.24. The keyword this can be compared to the words me, myself, and I.

Figure 6.25. Using the keyword this to differentiate between the method parameter and the instance variable

Figure 6.26. When a class mentions super, it refers to its direct parent or the base class.

Figure 6.27. Relationships among the classes Employee, Programmer, and Manager

Figure 6.28. The objects are aware of their own type and execute the overridden method defined in their own class, even if a base class variable is used to refer to them.

Figure 6.29. Relationships among classes Employee, Programmer, and Manager and the interface MobileAppExpert

Figure 6.30. Modified relationships among the classes Employee, Manager, and Programmer, and the interface MobileAppExpert

Figure 6.31. What’s accessible to the variable expert1

Figure 6.32. A Lambda expression and its mandatory sections

Chapter 7. Exception handling

Figure 7.1. Getting a taste of exceptions in Java

Figure 7.2. An example of ArrayIndexOutOfBoundsException

Figure 7.3. An example of FileNotFoundException

Figure 7.4. An example of StackOverflowError

Figure 7.5. Expected code flow lost in combating exception conditions, without separate exception handlers

Figure 7.6. Defining exception-handling code separate from the main code logic

Figure 7.7. Tracing the line of code that threw an exception at runtime

Figure 7.8. Categories of exceptions: checked exceptions, runtime exceptions, and errors

Figure 7.9. Class hierarchies of exception categories

Figure 7.10. Using throw and throws to create methods that can throw exceptions

Figure 7.11. Propagation of an exception through multiple method calls

Figure 7.12. Modified flow of control when an exception is thrown

Figure 7.13. A little humor to help you remember that a finally block executes regardless of whether an exception is thrown

Figure 7.14. The finally block executes even if an exception handler defines a return statement.

Figure 7.15. The order of placement of exception handlers is important.

Figure 7.16. A visual way to remember that the order matters for exceptions caught in the catch blocks

Figure 7.17. Class hierarchy of ArrayIndexOutOfBoundsException

Figure 7.18. Class hierarchy of ClassCastException

Figure 7.19. Class hierarchy of IllegalArgumentException

Figure 7.20. Class hierarchy of NullPointerException

Figure 7.21. Class hierarchy of ArithmeticException

Figure 7.22. Class hierarchy of NumberFormatException

Figure 7.23. Class hierarchy of xceptionInInitializerError

Figure 7.24. Class hierarchy of StackOverflowError

Figure 7.25. Class hierarchy of NoClassDefFoundError

Figure 7.26. Class hierarchy of OutOfMemoryError

Appendix Answers to Twist in the Tale exercises

Figure A.1. Evaluation of an expression that has multiple unary operators in postfix and prefix notation

Figure A.2. In an expression that uses the short-circuit operators && and ||, the operands that are evaluated are circled and the ones that aren’t evaluated are enclosed in rectangles.

Figure A.3. Array multiStrArr and its elements

Figure A.4. Flow of execution of code in Twist in the Tale 5.1

Figure A.5. UML notation of inheritance hierarchy of the classes Employee, Manager, and HRExecutive and the interface Interviewer

Figure A.6. The array oldLaptops

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.186.109