Summary: This module contains review questions and answers keyed to the module titled Jb0280: Java OOP: String and StringBuffer.
This module contains review questions and answers keyed to the module titled Jb0280: Java OOP: String and StringBuffer .
The questions and the answers are connected by hyperlinks to make it easy for you to navigate from the question to the answer and back again.
Java provides two different string classes from which string objects can be instantiated. What are they?
True or false? The StringBuffer class is used for strings that are not allowed to change. The String class is used for strings that are modified by the program. If false, explain why.
True or false? While the contents of a String object cannot be modified, a reference to a String object can be caused to point to a different String object. If false, explain why.
True or false? The use of the new operator is required for instantiation of objects of type String . If false, explain your answer.
True or false? The use of the new operator is required for instantiation of objects of type StringBuffer . If false, explain your answer
Provide a code fragment that illustrates how to instantiate an empty StringBuffer object of a default length and then use a version of the append method to put some data into the object.
Without specifying any explicit numeric values, provide a code fragment that will instantiate an empty StringBuffer object of the correct initial length to contain the string "StringBuffer named str6" and then store that string in the object.
Provide a code fragment consisting of a single statement showing how to use the Integer wrapper class to convert a string containing digits to an integer and store it in a variable of type int .
Explain the difference between the capacity method and the length method of the StringBuffer class.
True or false? The following is a valid code fragment. If false, explain why.
StringBuffer str6 =
new StringBuffer("StringBuffer named str6".length());Which of the following code fragments is the most efficient, first or second?
String str1 = "THIS STRING IS NAMED str1";
String str1 = new String("THIS STRING IS NAMED str1");Write a Java application that illustrates the fact that while a String object cannot be modified, the reference variable can be modified to point to a new String object, which can have the appearance of modifying the original String object.
Write a Java application that illustrates different ways to create String objects and StringBuffer objects.
Write a Java application that illustrates conversion from string to numeric.
What is the meaning of the following two images?
This image was inserted here simply to insert some space between the questions and the answers to keep them from being visible on the screen at the same time.
The image is also an example of the kinds of things that we do in my course titled ITSE 2321, Object-Oriented Programming.

This image was also inserted for the purpose of inserting space between the questions and the answers.
| Listing 1: File SampProg26.java. |
|---|
|
| Listing 2: File SampProg25.java. |
|---|
|
| Listing 3: File SampProg24.java. |
|---|
|
The first code fragment is the most efficient.
True.
The capacity method returns the amount of space currently allocated for the StringBuffer object. The length method returns the amount of space used.
int num = new Integer("3625").intValue();
StringBuffer str6 =
new StringBuffer("StringBuffer named str6".length());
str6.append("StringBuffer named str6");
StringBuffer str5 =
new StringBuffer();//accept default initial length
str5.append(
"StringBuffer named str5");//modify length as neededTrue.
False. A String object can be instantiated using either of the following statements:
String str1 = new String("String named str2");
String str2 = "String named str1";True.
False. This statement is backwards. The String class is used for strings that are not allowed to change. The StringBuffer class is used for strings that are modified by the program.
This section contains a variety of miscellaneous information.
Financial : Although the Connexions site makes it possible for you to download a PDF file for this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should be aware that some of the HTML elements in this module may not translate well into PDF.
I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.
In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please be aware that it is a copy of a module that is freely available on cnx.org and that it was made and published without my prior knowledge.
Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.
-end-