Meet your first object in Java.
One machine can build many different robots.
Use the same machine, but change the settings each time.
A class is the plan, and an object is one real example.
String"Hello"Some variables store values, and some store references.
int, double, and boolean store the value itself. String is your first important reference type in AP CSA. Now treat text in Java as an object.
String is the class name for this kind of text object. new String("Hello") creates one real string object. length() on it. Start with new, then compare the shorter form.
new tells Java to create a fresh object. "Hello" is the shorter form for the same kind of object. Use the dot operator to call a method on one object.
Common String methods at a glance.
Pick the correct result.
String methods usually return a new result.
word.substring(0, 3) alone does not replace the old string. word = word.substring(0, 3) to keep the new text. What is printed now?
What is printed by the first System.out.println(word) call?
A reference can also point to no object.
"" is a real string object, so its length is 0. null means the variable is connected to no object. length() on "", but not on null. Key ideas from today
A class is a blueprint. An object is one real instance.
String uses a reference, and that reference can also be null.
Use new to create an object. For String, quotes are the shorter form.
Use the dot operator to call methods, and save the new result when needed.
String variable.length().substring() result."java".