CIS1068 MIDTERM 1 (5) 1. What are milliseconds? megahertz? terabytes? (5) 2. Describe what is the Java Virtual Machine (5) 3. What does a compiler do (for instance the Java compiler javac)? (5) 4. Name the Java primitive data types. (10) 5. In Java an int is represented using 4 bytes. (a) How many values can be represented? (b) What value do I get if I add 1 to the largest positive integer? (10) 6. We are given an integer n. How do you compute the rightmost digit of n? [For example, if n is 376, the digit is '6'] (5) 7. Say what you know of integer overflow errors (5) 8. What is an identifier? (10) 9. Given an example of a data member, of a formal parameter, and of a local variable. (10) 10. Given an example of two franctions that are "equals" but not "==" (5) 11. What is the difference between a static data member and an instance data member? (5) 12. What is the value of the expression (show intermediate results): 20 < 3 % 3 + 5 / 3 * 17 || 3 == 3 && 3 < 1 (10) 13. Which of the following assignments is legal (I just give names of primitive types, to avoid having to write declarations): short = int; int = char; double = int; boolean = char; float = double; (10)14. After the declaration of String s = "violets are blue"; What is s.substring(3) s.substring(2, 6) s.indexOf("e") s.indexOf("e", 5) s.charAt(3) s.charAt(30) (10) 15. What is printed out by the following code fragment: String s1 = "x"; String s2 = "yy"; for (int k = 0; k<7; k=k+2) { System.out.print(s1 + s2); s1 += s1; s2 += s2; } (10)16. We find a piece of paper with on it written Moo.foo(2,3); What do you think it is Moo? and what is foo? On another piece of paper we find written joe.nom(2,3); What do you think it is joe? what is nom? (10)17. In the Fraction class complete the code for the method public Fraction subtract(Fraction a) { } which returns the difference of the subject fraction (i.e. the hidden parameter) and a. You can assume that you have available the constructor public Fraction(int n, int d); (15)18. Implement the method public static String unique(String s) which, given a string s, returns the string consisting of a single copy of each character in s. For example unique("abracadabra") is "abrcd". (15)19. Implement the method public static int count(String s1, String s2) that returns the number of occurrences of the string s2 in s1.