Chapter 3 Core Java APIs Flashcards
Using operators and decision constructs Creating and using arrays Working with selected classes from the Java API Working with Java Data Types
API stands for
application programming interface.
string is basically a sequence of [Blank]
characters
reference types are created using the [Blank] keyword
new
3 string concatenation rules:
- If both operands are numeric, + means numeric addition.
- If either operand is a String, + means concatenation.
- The expression is evaluated left to right.
System.out.println(1 + 2);
System.out.println(“a” + “b”);
System.out.println(“a” + “b” + 3);
System.out.println(1 + 2 + “c”);
3
ab
ab3
3c
int three = 3;
String four = “4”;
System.out.println(1 + 2 + three + four);
1 + 2 = 3
3 + three = 6
6 + four = 64
String s = “1”;
s += “2”;
s += 3;
System.out.println(s);
123
Can a String be changed when it is created?
No, String is immutable
[Blank] means changeable (as in StringBuffers/StringBuilders)
Mutable
Immutable classes in Java are [Blank], and subclasses can’t add mutable behavior.
final
String s1 = “1”;
String s2 = s1.concat(“2”);
s2.concat(“3”);
System.out.println(s2);
12
What location in the JVM collects Strings to reuse and save memory?
String Pool, also known as the intern pool
Which one uses the String pool? String name = "Fluffy"; String name = new String("Fluffy");
First one uses String pool.
Second one creates a new object
Java counts from [Blank] when indexed
0
String class method: length()
The method length() returns the number of characters in the String. The method signature is as follows:
String string = “animals”;
System.out.println(string.length()); // 7