Example Webinar on Strings

What are strings?

Ask students to explain what strings are and give some examples of declaring and initializing strings. You can point them to http://interactivepython.org/runestone/static/JavaReview-RU/Strings/sbasics.html if they don’t know.

Strings are objects that hold a sequence of characters. You can declare then using the class name and variable name (class names always start with an uppercase letter).

String name; // declares a string

You can initialize the value of a string using characters in a pair of double quotes or use the new operator to create a new String object.

String name = "Ja'Quan"; // declares and initializes a string
String name2 = new String("Maria"); // also declares and initializes a string

Strings are objects of the String Class

Run ActiveCode 2 on page http://interactivepython.org/runestone/static/JavaReview-RU/Strings/sbasics.html and show that every object keeps a reference to the class that created it and a class keeps track of the class it inherits from.

String methods

Show the methods that students need to know for the exam at http://interactivepython.org/runestone/static/JavaReview-RU/Strings/sMethods.html

Ask students to predict what ActiveCode 1 will print and then run it to find out. You can always change the code in ActiveCode 1 and ask them to predict again what it will print.

Try problems at Practice-It like http://practiceit.cs.washington.edu/problem.jsp?category=Building+Java+Programs%2C+3rd+edition%2FBJP3+Chapter+3&problem=bjp3-3-s20-stringExpressions2 Skip the methods that aren’t on the exam like charAt.

Go to http://interactivepython.org/runestone/static/JavaReview-RU/Strings/sMethods.html and ask students to predict what ActiveCode 2 will print and then run it to find out. Again you can change the code and ask them to predict the results.

Ask the students what the answers are for 4-2-3 through 4-2-5. Give them time to all try to solve them and then pick someone to explain what the answer is and why it is correct.

String Equality

Go to http://interactivepython.org/runestone/static/JavaReview-RU/Strings/sEquality.html and ask students to predict what ActiveCode 1 will print. Then run it.

Ask a student to explain the difference between equals and ==. You can use Figure 3 to show how they work.

Ask students to predict what will happen when you run ActiveCode 2. Then run it .

Have students solve 4-3-1 and ask a student to explain the correct answer.

String Concatenation

Ask a student to explain what happens when you concatenate strings together. See http://interactivepython.org/runestone/static/JavaReview-RU/Strings/sOperators.html if they don’t know.

Ask students to predict what will happen when they run ActiveCode 2. Then run it and explain what happens.

Common Mistakes

Ask students what they think the common mistakes are with strings.

Show students http://interactivepython.org/runestone/static/JavaReview-RU/Strings/sMistakes.html

Practice with writing string code

Go to http://codingbat.com/java/String-1 and have students practice writing simple string processing code.

The following problems can be done at this point (don’t require conditionals or loops). You will have to explain that they can use the keyword return to return a value from a method.

Practice with multiple choice questions

Try some of the medium multiple choice questions at http://interactivepython.org/runestone/static/JavaReview-RU/Strings/sMedMC.html

Ask students to try to solve the problem and then assign each answer to a student and ask the student to explain why that answer is right or wrong. One of the things that you are trying to do is help students figure out how to eliminate wrong answers quickly.

You can also copy code from a multiple choice question and put it in an ActiveCode window to run it.

Next Section - Free Response Webinars