1 / 61

UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000

UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000. Lecture 23: Review Mon. 12/11. Course Grading. Homework 40% Exam 1 15% (closed book) Exam 2 20% (open book, notes ) Exam 3 25% (open book, notes). Results are scaled if necessary.

eyal
Download Presentation

UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UMass Lowell Computer Science 91.460Java and Distributed ComputingProf. Karen DanielsFall, 2000 Lecture 23: Review Mon. 12/11

  2. Course Grading • Homework 40% • Exam 1 15% (closed book) • Exam 2 20% (open book, notes ) • Exam 3 25% (open book, notes) Results are scaled if necessary.

  3. Final Exam: Logistics We’re trying to change this to OS 311. It looks like OS 311 is available. • Thursday, 12/21 • Olsen 410 8:00-10:00 a.m. • Open book, open notes • Closed computers, neighbors • Cumulative • Worth 25% of grade

  4. Text/Chapter Coverage • Basic Java (Deitel): • Chapters: 1-10, 14, 17 • Advanced Java (Deitel): • Chapters: 11-13, 15, 20, 22-24 • Jini (Core Jini): • Chapters: 1, 2, 3, 5 & (attribute matching) • Appendix A All questions refer to Java 2 unless otherwise specified.

  5. Format and Emphasis This exam will have a mixture of questions of the following types: 1) Multiple Choice 2) Short Answer 3) Debugging 4) Fill-in-the-blanks 5) Write a variation on code 6) Code from scratch

  6. Review: Part I Basic Java

  7. Sampling of Topics • Applets • Applications • Data Types • Operators • Expressions • Interfaces • Control Structures • Recursion • Packages • Object-Oriented • Classes (and inner) • Methods • Polymorphism • Files & Streams • Chaining • Object serialization

  8. A B x=2 foo() B A x=1 foo() Polymorphism is for Methods A::foo() B::foo() B::foo() a.x=1 b.x=2 ((A)b).x=1 Thanks Jenn for this example

  9. Typical Multiple Choice Question • Which statement is true about a non-static inner class? A) It must implement an interface. B) It is accessible from any other class. C) It can only be instantiated in the enclosing class. D) It must be final, if it is declared in a method scope. E) It can access private instance variables in the enclosing object. An object of a non-static inner class is able to access private variables of the outer class in which it is defined. From Java 2 Certification

  10. Typical Multiple Choice Question • Which of the following are true? A) If a package statement is included in a source code file, it must appear as the first non-blank* line. B) If an import statement is included in a source code file, it must appear as the first non-blank* line. C) If a main( ) method is included in a source code file, it must appear as the first non-blank* line. D) If a public interface is declared in a source code file, it must have the same name as the source code file. Package statements must appear as the first “non-blank” line of a source code file if they appear at all. If a public class or interface is declared in a source file, then the source code file must take the name of the public class or interface. * a comment line is considered here as a blank line From Java 2 Certification

  11. Typical Short Answer Question • What is the output of the following program? public class Question{ public static void main(String args[]) { double d[] = new double[2]; int i[] = new int[3]; Object o[] = new Object[1]; System.out.print(d[0] + i[2]); System.out.println(o[0] + "ify"); } } 0.0nullify The default value of a double is 0.0. The default value of an int is 0. Their sum is 0.0. (This arithmetic expression is evaluated and then the resulting value is cast to a string so it is a valid argument to the print() method. In contrast, if we changed the expression to the following, it would cease to be an arithmetic expression and would become a string expression: System.out.print(“ “ + d[0] + i[2]). This would produce a different result.) The default value of an Object is null. Adding “ify” gives “nullify”

  12. Typical Short Answer Question • What is the output of the following program? public class Question{ public static void main(String args[]) { String s1 = “ab”; String s2 = “abcd”; String s3 = “cd”; String s4 = s1 + s3; s1 = s4; System.out.print(“s1 ”+((s1 == s2)? “==” : “!=”)+“ s2”); } } s1 != s2 Because s1 and s2 refer to different objects, s1 != s2 is true. From Java 2 Certification

  13. Typical Short Answer Question • What is the value of 9 + 8 % 7 + 6 16 Order of precedence requires that the expression be evaluated as: (9 + (8 % 7) + 6) From Java 2 Certification

  14. Typical Debugging Question public int sum(int i[], Integer start, Integer end){ if(start == end) return i[start.intValue()]; else { Integer mid = new Integer((start.intValue() + end.intValue())/2); Integer mid1 = new Integer((start.intValue() + end.intValue())/2 +1); return sum(i, start, mid) + sum(i, mid1, end); } } // Note: You can correct the code while still using the Integer wrapper class. // We removed it here only for clarity. If you don’t remove it, you need to // change start == end accordingly. public int sum(int i[], int start, int end) { if(start == end) return i[start]; else return sum(i, start, (start+end)/2) + sum(i, ((start+end)/2) + 1, end); } This code is supposed to recursively sum the values of the elements of integer array i. For each recursive call, the starting and ending indices of the part of the array to be summed should be in start and end, respectively. What is wrong with the code?

  15. Typical Fill-in-the-Blanks (page 1) public void closeInputFile(BufferedReader input, String fileName) { try { input.close(); } catch (IOException e) { System.out.println("Cannot close "+ fileName); } } public BufferedReader openInputFile(String fileName) { BufferedReader input = null; try { InputStreamReader inStream = new InputStreamReader(new FileInputStream(fileName)); input = new BufferedReader(inStream); } catch (IOException e) { System.out.println("Cannot open "+ fileName); } return input; } This code opens and closes a file whose name is given by the String fileName.

  16. Typical Fill-in-the-Blanks (page 2) public void readFile(String fileName) { BufferedReader inStream = openInputFile(fileName); newString = readFileLine(inStream); closeInputFile(inStream, fileName); } public String readFileLine(BufferedReader inStream) { String newString = null; return newString; } boolean lineNotEmpty = true; String newString = null; while (lineNotEmpty){ if (newString == null || newString.length()==0) lineNotEmpty = false; else System.out.println("Just read:"+ newString); } try{ newString = inStream.readLine(); } catch (IOException e) { System.out.println("Cannot read file line in readFileLine"); } Fill in the blanks so that readFile( ) reads and prints out all the lines in the file.

  17. Review: Part II Advanced Java

  18. Sampling of Topics • GUI components (awt, Swing) • JPanel JLabel • JButton JList • JFrame JScrollPane • Container • Layout policy • Event handling • Event listeners • 2D graphics • Advanced data structures • ArrayList, iterator • Threads • time synchronization • creation, scheduling • mutual exclusion • states & transitions • synchronized methods & blocks • Exception handling • RMI: remote interface proxy • One interface, multiple implementations

  19. Review Questions • Typical multiple choice questions • exception handling • mutual exclusion • RMI • event handling • Typical short answer questions • event handling • threads • graphics • Typical write-a-variation questions • ArrayList • Typical fill-in-the-blanks question • Typical code-from-scratch question

  20. Typical Multiple Choice Question • Which of the following must be true of the object thrown by a throw statement? A) It must be assignable to the Throwable type. B) It must be assignable to the Error type. C) It must be assignable to the Exception type. D) It must be assignable to the String type. The object thrown by a throw statement must be assignable to the Throwable type. This includes the Error and Exception types. From Java 2 Certification

  21. Typical Multiple Choice Question • Which of the following are true? A) Only threads have locks. B) Classes have locks. C) Primitive types have locks. D) Only Runnable objects have locks. Classes have locks, but primitive types do not. From Java 2 Certification

  22. Typical Multiple Choice Question • Which of the following are used by Java RMI? A) stubs B) skeletons C) ORBs D) IIOP RMI makes use of stubs and skeletons. ORBs and IIOP are used within CORBA. [Note: Java 2 does not require skeletons] Based on Java 2 Certification

  23. Typical Multiple Choice Question • What is the preferred way to handle an object’s events in Java 2? A) Override the object’s handleEvent() method. B) Add one or more event listeners to handle the events. C) Have the object override its processEvent() methods. D) Have the object override its dispatchEvent() methods. The event-delegation model uses event listeners to handle events. From Java 2 Certification

  24. Typical Short Answer Question • Supposed you want to have an object eh handle the TextEvent of a TextArea object t. How should you add eh as the event handler for it? t.addTextListener(eh); You must invoke the TextArea object’s addTextListener( ) method and pass it a reference to the event handler. From Java 2 Certification

  25. Typical Short Answer Question • What is the output of the following program? public class Question{ public static void main(String args[]) { MyThread t = new MyThread(); t.displayOutput(“t has been created.”); t.start(); } } class MyThread extends Thread{ public void displayOutput(String s) { System.out.println(s); } public void run() { displayOutput(“t is running.”); } } t has been created. t is running. From Java 2 Certification

  26. Typical Short Answer Question:What is the output of the following program?

  27. Typical Short Answer

  28. Typical Short Answer Question:What is the output of the following program?

  29. Typical Short Answer

  30. Typical Coding Variation Question:Modify this code so it removes Color objects from the list but not Strings continued on next slide...

  31. Typical Coding Variation Question:Modify this code so it removes Color objects from the list but not Strings ArrayList: java.awt.Color[r=255,g=0,b=255] red white blue java.awt.Color[r=0,g=255,b=255] ArrayList after calling removeStrings: java.awt.Color[r=255,g=0,b=255] java.awt.Color[r=0,g=255,b=255]

  32. Typical Coding Variation Answer continued on next slide...

  33. Remote Interface NextNumber.java Client using Service NextNumberClient.java NextNumberImpl.java Service implementing Remote Interface Typical Fill-in-the-Blanks Question • RMI: making a service into a service+client for transformation from 2-tier to 3-tier.

  34. Remote Interface NextNumber.java Typical Fill-in-the-Blanks Question(continued) // A remote interface for getting the next number import java.rmi.Remote; import java.rmi.RemoteException; public interface NextNumber extends Remote { public int getNextNumber(int n) throws RemoteException; }

  35. NextNumberImpl.java Service implementing Remote Interface Typical Fill-in-the-Blanks Question(continued)

  36. NextNumberImpl.java Service implementing Remote Interface Typical Fill-in-the-Blanks Question(continued)

  37. Client using Service NextNumberClient.java Typical Fill-in-the-Blanks Question(continued)

  38. Client using Service NextNumberClient.java Typical Fill-in-the-Blanks Question(continued)

  39. Typical Fill-in-the-Blanks Question(continued) • Fill-in-the-blanks so that the next number service obtains the next number from a secret service instead of just adding one to the number. You may assume that the interface of the secret service is: // A remote secret interface for getting the next number import java.rmi.Remote; import java.rmi.RemoteException; public interface Secret extends Remote { public int getSecretNextNumber(int n) throws RemoteException; }

  40. Typical Fill-in-the-Blanks Question(continued)

  41. Typical Fill-in-the-Blanks Question(continued)

  42. Typical Fill-in-the-Blanks Question(continued)

  43. Typical Code-from-Scratch Question • Write code to simulate n bank patrons using safe deposit boxes. • Assume bank patron i already is assigned safe deposit box i. • Only 1 box in the bank is accessible at a time. • To access a box, patron needs his/her key and the bank's key for their box. • Assume patron already has his/her key, so we don't model that. • However, they need to get lock on bank key and box.

  44. Typical Code-from-Scratch Question(continued)

  45. Typical Code-from-Scratch Question(continued)

  46. Typical Code-from-Scratch Question(continued)

  47. Typical Code-from-Scratch Question(continued)

  48. Typical Code-from-Scratch Question(continued)

  49. Review: Part III Jini

  50. Sampling of Topics • Basic client, service • HTTP servers • Lookup service • Matching services • Interfaces/proxy • Leasing • Delegation/ 3rd party delegation • RMI activation • Remote events & event model • Federating communities • Security • Well-behaved service

More Related