Chapter 4. Selected classes from the Java API and arrays

Exam objectives covered in this chapter

What you need to know

[9.2] Creating and manipulating Strings How to initialize String variables using = (assignment) and new operators. Use of the operators =, +=, !=, and == with String objects. Pooling of string literal values. Literal value for class String. Use of methods from class String. Immutable String values. All the String methods manipulate and return a new String object.
[3.2] Test equality between Strings and other objects using == and equals(). How to determine the equality of two String objects. Differences between using operator == and method equals() to determine equality of String objects.
[9.1] Manipulate data using the StringBuilder class and its methods. How to create StringBuilder classes and how to use their commonly used methods. Difference between StringBuilder and String classes. Difference between methods with similar names defined in both of these classes.
[4.1] Declare, instantiate, initialize, and use a one-dimensional array. How to declare, instantiate, and initialize one-dimensional arrays using single and multiple steps. The do’s and don’ts of each of these steps.
[4.2] Declare, instantiate, initialize, and use a multidimensional array. How to declare, instantiate, and initialize multidimensional arrays using single and multiple steps, with do’s and don’ts for each of these steps. Accessing elements in asymmetric multidimensional arrays.
[9.4] Declare and use an ArrayList of a given type. How to declare, create, and use an ArrayList. Advantages of using an ArrayList over arrays. Use of methods that add, modify, and delete elements of an ArrayList.
[9.3] Create and manipulate calendar data using classes from java.time.LocalDateTime, java.time.LocalDate, java.time.LocalTime, java.time.format.DateTimeFormatter, java.time.Period. How to store dates and times using classes LocalDate, LocalTime, and LocalDateTime. Identify the factory methods to instantiate date and time objects. Use instance methods of date and time classes. Use Period to add or subtract duration (days, months, or years) to and from date objects. Use DateTimeFormatter to format or parse date and time objects.

In the OCA Java SE 8 Programmer I exam, you’ll be asked many questions about how to create, modify, and delete String objects, StringBuilder objects, arrays, ArrayList objects, and date/time objects. To prepare you for such questions, in this chapter I’ll provide insight into the variables you’ll use to store these objects’ values, along with definitions for some of their methods. This information should help you apply all the methods correctly.

In this chapter, we’ll cover the following:

  • Creating and manipulating String and StringBuilder objects
  • Using common methods from classes String and StringBuilder
  • Creating and using one-dimensional and multidimensional arrays in single and multiple steps
  • Accessing elements in asymmetric multidimensional arrays
  • Declaring, creating, and using an ArrayList and understanding the advantages of an ArrayList over arrays
  • Using methods that add, modify, and delete elements of an ArrayList
  • Creating date and time objects using the classes LocalDate, LocalTime, and LocalDateTime
  • Manipulating date objects using the class Period
  • Formatting and parsing date and time objects using DateTimeFormatter

Let’s get started with the class String.

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

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