Chapter Introduction
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
Chapter 1. Java basics
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.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.12. A subpackage and its corresponding class definition
Figure 1.13. Matching directory structure and package hierarchy
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.26. Classes that can access protected members
Figure 1.27. Understanding class representation for default access
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
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.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.14. Differences between object reference variables and primitive variables
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.7. The scopes of variables can overlap.
Figure 3.8. Comparing the scope, or life span, of all four variables
Figure 3.10. Objects can be dereferenced by reassignment of variables.
Figure 3.13. Different types of methods
Figure 3.17. Real-life examples of overloaded methods
Figure 3.19. A class, Employee, with a constructor defined by the user Paul
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.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.6. Mapping characters stored by a String with the positions at which they’re stored
Figure 4.8. Categorization of the String methods
Figure 4.10. The characters "ABCAB" stored by String
Figure 4.11. The String "Oracle"
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.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.23. Array declaration creates a variable that refers to null.
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.3. The classes Programmer and Manager extend the class Employee.
Figure 6.6. An object of a derived class can access features of its base class object.
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.18. A variable of type Employee can see only the members defined in the class Employee.
Figure 6.20. All types of Employees can attend an office party.
Figure 6.24. The keyword this can be compared to the words me, myself, and I.
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
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.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.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.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
Appendix Answers to Twist in the Tale exercises
Figure A.3. Array multiStrArr and its elements
Figure A.4. Flow of execution of code in Twist in the Tale 5.1
18.189.186.109