Podcast
Questions and Answers
Which operator is used to perform string concatenation in Java?
Which operator is used to perform string concatenation in Java?
- *
- + (correct)
- -
- //
What does the following expression do: greeting.toUpperCase()
if a String variable called greeting contains the characters 'hello'?
What does the following expression do: greeting.toUpperCase()
if a String variable called greeting contains the characters 'hello'?
Returns a new string containing the characters 'HELLO'
What is the result of the following expression: pioneer.length()
if a string variable called pioneer contains the characters 'Grace Murray Hopper'?
What is the result of the following expression: pioneer.length()
if a string variable called pioneer contains the characters 'Grace Murray Hopper'?
19
Given the following declaration, which expression would extract the substring 'ledge'? String words = 'Knowledge is power.'
Given the following declaration, which expression would extract the substring 'ledge'? String words = 'Knowledge is power.'
What output would be produced when the following is executed:
String state = 'Mississippi';
System.out.println(state.replace('is', 'was'));
What output would be produced when the following is executed:
String state = 'Mississippi';
System.out.println(state.replace('is', 'was'));
If a String variable called address contains the characters '123 Main Street', what is the result of the following expression: address.indexOf('3')
?
If a String variable called address contains the characters '123 Main Street', what is the result of the following expression: address.indexOf('3')
?
Which statement would produce the following output: 'Oom Pah Pah Oom Pah Pah,' that's how it goes?
Which statement would produce the following output: 'Oom Pah Pah Oom Pah Pah,' that's how it goes?
Which of the following literals is NOT valid?
Which of the following literals is NOT valid?
What is the output of the following statement: System.out.println('He said "Avada Kedavra"');
?
What is the output of the following statement: System.out.println('He said "Avada Kedavra"');
?
What is '\t'?
What is '\t'?
What is '\n'?
What is '\n'?
What do the characters in a Unicode escape sequence represent?
What do the characters in a Unicode escape sequence represent?
What is a small character set containing primarily English characters and basic symbols?
What is a small character set containing primarily English characters and basic symbols?
What is a way to represent non-ASCII Unicode characters in a program?
What is a way to represent non-ASCII Unicode characters in a program?
What is the technique of ordering characters based on a character set?
What is the technique of ordering characters based on a character set?
What is the way characters are stored in memory?
What is the way characters are stored in memory?
What are characters that don't map to the fixed-width, 16-bit Unicode encoding?
What are characters that don't map to the fixed-width, 16-bit Unicode encoding?
What are characters (like newline) that have no visual symbol?
What are characters (like newline) that have no visual symbol?
What is the character set Java uses to represent characters?
What is the character set Java uses to represent characters?
What is a list of characters used by a programming language?
What is a list of characters used by a programming language?
The String class is part of the java.__ package.
The String class is part of the java.__ package.
Two classes can have the same name if they are in different ____.
Two classes can have the same name if they are in different ____.
In a program, a class must always be referred to using its fully qualified name.
In a program, a class must always be referred to using its fully qualified name.
An ___ ___ tells the compiler which class you're referring to in a program.
An ___ ___ tells the compiler which class you're referring to in a program.
An import statement should be written ____ a class.
An import statement should be written ____ a class.
The classes of the . package are automatically imported into every Java program.
The classes of the . package are automatically imported into every Java program.
An entire package can be imported using ___ import statement(s).
An entire package can be imported using ___ import statement(s).
A __ __ lets you refer to a static method without using its class name.
A __ __ lets you refer to a static method without using its class name.
The Java keyword new is ____ __.
The Java keyword new is ____ __.
A constructor of a class has the ____ ____ as the class, and is called when ____ ____ ____ ___.
A constructor of a class has the ____ ____ as the class, and is called when ____ ____ ____ ___.
An object does not have to be created when its object reference variable is declared.
An object does not have to be created when its object reference variable is declared.
Following a ____ reference will cause an exception to be thrown.
Following a ____ reference will cause an exception to be thrown.
A String object can be created with a new operator.
A String object can be created with a new operator.
A String method can be called through a ____ __.
A String method can be called through a ____ __.
What will happen if the variable total holds 5 when the following code is executed?
if (total > 8)
System.out.println("collywobbles");
What will happen if the variable total holds 5 when the following code is executed?
if (total > 8)
System.out.println("collywobbles");
Flashcards are hidden until you start studying
Study Notes
String Manipulation in Java
- String concatenation in Java uses the
+
operator. - Method
toUpperCase()
converts all characters in a String to uppercase, e.g., "hello" becomes "HELLO". - The
length()
method returns the number of characters in a String, e.g., "Grace Murray Hopper" has a length of 19. - The method
substring(startIndex, endIndex)
extracts a portion of a String; for "Knowledge is power.",words.substring(4, 9)
returns "ledge". - Using
replace(oldChar, newChar)
modifies a String, as in the case of "Mississippi" to "Mwasswassippi" by replacing "is" with "was". - The
indexOf(char)
method returns the index of the first occurrence of a character in a String, e.g.,'3'
in "123 Main Street" is at index 2.
Output Control
- To print special characters or formatted strings, escape sequences like
\"
are used. For example,System.out.println("\"Oom Pah Pah Oom Pah Pah,\" that's how it goes.");
prints with quotation marks. - Valid and invalid string literals include options with escape characters; option c
""\n""
is invalid.
Character Handling
- The escape sequence
\t
represents a horizontal tab, while\n
denotes a newline character. - Unicode escape sequences specify characters in hexadecimal format for non-ASCII characters. ASCII refers to a small character set primarily for English and symbols.
- Lexicographic ordering is the technique used to order characters based on a character set, which in Java is represented by Unicode.
Memory and Encoding
- Character encoding determines how characters are stored in memory, with supplementary characters representing those that don't fit into fixed-width encodings.
- Non-printable characters, such as newline, do not have visual symbols.
Java Package System
- The String class belongs to the
java.lang
package, which is auto-imported into every Java program. - Classes can share names if they are in different packages; however, their fully qualified names do not always need to be used in the code.
- An import statement specifies which class to reference in a program and should be placed above the class definition.
- A static import allows direct access to static methods without needing to reference the class name.
Objects and Constructors
- The keyword
new
is an operator used to create new objects, and a class constructor has the same name as the class. - Objects can be declared without being instantiated immediately. A null reference will raise an exception if accessed.
- A String object can indeed be created with the
new
operator, and String methods can also be called on String literals.
Control Flow
- Conditional statements evaluate expressions, e.g., if a total of 5 is compared in an
if
statement with a value of 8, it does not execute the inner statement, resulting in no output and continued processing.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.