Core Java APIs
0430-0506
Exam objectives
Using Operators and Decision Constructs
Test equality between Strings and objects using == and equals().
Creating and Using Arrays
Declare, instantiate, initialize and use a one-dimensional array.
Declare, instantiate, initialize and use a multi-dimensional array.
Working with Selected classes from the Java API
Creating and manipulating Strings.
Manipulate data using the StringBuilder class and its methods.
Declare and use an ArrayList of a given type.
Create and manipulate calendar data using classes from java.time.LocalDateTime, java.time.LocalDate, java.time.Local-Time, java.time.format.DateTimeFormatter, java.time.Period.
Working with Java Data Types
Develop code that uses wrapper classes such as Boolean, Double, and Integer.
Notes
Creating and Manipulating Strings
A string is basically a sequence of characters.
String class is a special class, doesn't need to be instantiated with new.
String name = "Fluffy";
String name = new String("Fluffy");
Concatenation
Placing String before the other String and combining them together is called string concatenating. The + operator can be used in two ways within the same line of code:
If both operands are numeric, + means numeric addition.
If either operand is a String, + means concatenation.
The expression is evaluated left to right.
ie.
Immutability
String objects are immutable, once they are created, they can not be made larger or smaller, and you cannot change one of the characters inside them.
The String Pool
Strings are everywhere in Java, they use up a lot of memory, Java solves this issue by reusing common ones. The
string pool
, also known as the intern pool, is a location in the JVM that collects all these strings.The string pool contains literal values that appear in your program. Strings not in the string pool are garbage collected just like any other object.
The second way is less efficient than the first way, however, it is allowed.
Important String Methods
A string is a sequence of characters and zero-indexed.
length()
Returns the number of characters in the String.
charAt()
Lets you query the string to find out what character is at a specific index.
Indexes start counting with 0.
indexOf()
Last updated