1Strings and Arrays2/7/20082Opening Discussion■Do you have any questions about the assignment?■What is the purpose of generics?■What is the syntax of generics?■What are enums?■What is the syntax of Java enums?■What are inner classes? What makes them special? What types of inner classes are there?■What is the syntax of inner classes?3Strings■How did you represent a string in C? How do we represent a string in Java?■Let's go look at the API for String to see what the Java developers have provided us with.■Strings are immutable so it is very inefficient to build big strings from a lot of little pieces. If you need to do that, use StringBuffer.■It is the only class with an overloaded operator, + for string concatenation.■Functions that looks they mutate the String return a new String instead.■To get a single character, use charAt.4Code■To give us a chance to play with strings some let's go ahead and write that code that parses text formulas into a polymorphic tree for fast evaluation.5Regular Expressions■You'll notice that some of the methods in String say that they take regular expressions (regex). This is a topic that we won't directly cover in this class, but it is a very powerful technique for you to learn.■The java.util.regex package contains the two main classes that are used for regular expressions. The Pattern class has a lot of description about them at the top.6Arrays■Array syntax in Java is just like it was in C as far as using the arrays. There are significant differences though.■Array types are made by putting [] after a regular type.■Array types are object types so your variables are references and should be instantiated with new.■Arrays have bounds checking and know their length.■You can't make arrays of generics.7Code■With whatever time is left I want to go play with the ray tracer some now. We can make an array of Geomerty objects.■Note that arrays of objects store an array of references. This allows for inclusion polymorphism with arrays.8Minute Essay■Write the following method:String replaceAll(String s,char f,char t)■This method should return a new string where all instances of f in s have been replaced with t.■Remember to submit your code for assignment #1 today.■The first quiz is next class.■Interclass Problem – Write a program where a user types in a line of text and you print out each word in the line and the number of characters in
View Full Document