Ch 8: Strings Flashcards
in java, what is a string of characters represented by
an object of the String type
characteristics of String objects are
have methods
can be passed to other methods (always as references) or returned from methods
literal strings are
represented by text in double quotes ex: “Twitter”
what operators can be used to concatenate a string with another string, number , or an object
+ and +=
what is concatenation
combining of two strings with + or +=
what are escape characters
\ is used as the escape character ex: \n, \t, ", \
can a literal string be empty
yes, it is called an empty string ex: String s = “”;
do literal strings objects need to be created
even though they act as string object, they do not have to be created
explain String city = “Boston”;
sets the reference city to a String object “Boston”. Boston is not the name of the variable (its name is city). Boston is its value
the String class has over a dozen constructors, true or false
true, but it is less common to use constructors for strings than for other types of objects
is there a difference between String str = “Foo Fighters”; and String str = new String(“Foo Fighters”);
yes, but a far as your programmed is concerned, the two declarations act identically
what is the field of the String type set as default
private String Hello;
null
explain String s1 = “”;
s1 is set to an empty string
explain String s2 = new String();
s2 is set to an empty string
what happens when a method is called for a reference that is equal to null
program throws a NullPointerException and quits