Extra Credit Questions

Questions

Title Question
Why is it called double? Why is the data type for decimal numbers called double in Java?
Architecture Which famous architecture are most of today’s CPUs modeled after?
Unary Operators What are some of the unary operators in Java? List their symbol and meaning (semantics).
String Comparison In lecture, we mentioned that the equals() and equalsIgnoreCase() methods are required to be used to compare strings as strings are reference types in Java. That is, using the equality operator (==) would compare the reference values held in the variables as opposed to the individual characters in the strings. However, we demonstrated that, at least for the example given, we can use the equality operator to achieve the same result. Why is that?
Multiple method declarations The method declaration corresponding to a method call changes for multiple methods having the same name but differing in the number and types of parameters. What is this called in Java?
Define numberOfLowerCaseCharacters() Define a method (that is, give the method definition) that returns the number of lowercase characters contained in a String (see below code snippet for details).
Generalize hasNumberOfSpaces() Generalize the hasNumberOfSpaces() method listed below to check for the count of arbitrary characters. That is, the hasNumberOfSpaces() method currently considers only spaces, however, there is nothing very special about a space. A space is just a character. In theory, the method could easily check for other characters in a very similar fashion. Instead of having this method specifically check for spaces, make the method more general to check for the character of the caller’s choosing. For example, the caller (i.e., the calling method) may want to check for the count of the letter 'b' in str. Note that you may need to add parameter(s) and/or change the name of the method. Make sure to test your method by writing a main() method than calls it.
UML tool Find a software tool that allows you to generate UML diagrams and generate code from the diagrams. Then, use it to draw a UML diagram and generate the corresponding code. Upload a screen shot of the diagram and the generated code.
Overloading When you overload a method in Java, does the return type need to be the same?
static imports What is a static import in Java? How is it used?
Where are objects stored? Objects are stored in a special place of memory in Java. What is the portion of memory called where objects are stored?
Printing an entire array question How may one print the contents of an entire array using a single Java statement and using the Java API? Hint: Have a look at the methods in java.lang.Arrays.
Initial value of array elements In Java, is there an initial value of array elements when the array is declared? If so, what is it?
Character test Why is ‘z’ > ‘Z’?
What is a Turing machine? What is a Turing machine and how is it related to the paper with a hole anology used in class?

Details

numberOfLowerCaseCharacters()

/**
* Returns the number of lowercase characters contained in the String str.
* @param str The String in which to count the lowercase characters.
* @return The number of lowercase characters in str.
*/
public static int numberOfLowerCaseCharacters(String str) {
//...
}

hasNumberOfSpaces()

/**
* Returns true if the given string contains the given number of spaces and false otherwise.
* For example, both hasNumberOfSpaces("Pete", 0) and hasNumberOfSpaces("LeBron James", 1) would return true,
* while both hasNumberOfSpaces("DeGrom", 1) and hasNumberOfSpaces("Dogs are great", 10) would return false.
*
* @param str The string in which to check for spaces.
* @param numSpaces The number of spaces in which to check.
* @return True if str has numSpaces number of spaces and false otherwise.
*/
public static boolean hasNumberOfSpaces(String str, int numSpaces) {
//...
}