{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

13_Review Lecture

13_Review Lecture - Final Review Lecture Final Exam Mul4ple...

Info icon This preview shows pages 1–18. Sign up to view the full content.

View Full Document Right Arrow Icon
Final Review Lecture
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Final Exam Mul4ple choices with a single correct answer (10%) Short answer ques4ons (20%) Basic OOP (10%) Polymorphism Object ini4aliza4on Interface and Inner class (10%) Excep4on Handling (15%) Generics (15%) Mul4threading (20%)
Image of page 2
General Scope Every topic covered in the course so far will be examined. Final exam will focus on principles and ra4onales. Final exam will not focus on API usages except: Common opera4ons on Strings Thread/Runnable/wait() and no4fy()
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Excep4on Handling
Image of page 4
Review Points Basic syntax of declaring/catching excep4ons Difference between checked and unchecked excep4ons. Rethrowing excep4ons Matching mul4ple excep4ons Finally blocks
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Checked Exceptions vs. Unchecked Exceptions 6 RuntimeException , Error and their subclasses are known as unchecked exceptions . All other exceptions are known as checked exceptions , meaning that the compiler forces the programmer to check and deal with the exceptions.
Image of page 6
Catch or Declare Checked Exceptions Java forces you to deal with checked exceptions. If a method declares a checked exception (i.e., an exception other than Error or RuntimeException ), you must invoke it in a try-catch block or declare to throw the exception in the calling method. For example, suppose that method p1 invokes method p2 and p2 may throw a checked exception (e.g., IOException ), you have to write the code as shown in (a) or (b). 7
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Rethrowing Exceptions try { statements; } catch(TheException ex) { perform operations before exits; throw ex; // throw new TheException(); } 8
Image of page 8
The finally Clause try { statements; } catch(TheException ex) { handling ex; } finally { finalStatements; } 9 1. Uncaught excep4on in normal flow; 2. Return in error flow
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Catching Exceptions try { statements; // Statements that may throw exceptions } catch (Exception1 exVar1) { handler for exception1; } catch (Exception2 exVar2) { handler for exception2; } ... catch (ExceptionN exVar3) { handler for exceptionN; } 10
Image of page 10
Be Careful with Mul4ple Excep4ons Note that the following will produce a compiling error. Why? try {…} catch (Exception e3) {…} catch (ArithmeticException e1){…} catch (IOException e2) {…} MultipleException
Image of page 11

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Generics
Image of page 12
Review points Basic syntax of declaring/using a generic type. Basic syntax of declaring/using a generic method Wild card matching and support of polymorphism Bounded parameter types ? super/extends PECS principle
Image of page 13

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Generic Type 14 Generic Instan4a4on Runtime error Compile error Improves reliability GenericMotivation _interfaces.ComparableRectangle, ComparableRectangleWithGeneric
Image of page 14
Generic ArrayList in JDK 1.5 15
Image of page 15

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
No Casting Needed ArrayList<Double> list = new ArrayList<Double>(); list.add(5.5); // 5.5 is automatically converted to new Double(5.5) list.add(3.0); // 3.0 is automatically converted to new Double(3.0) Double doubleObject = list.get(0); // No casting is needed double d = list.get(1); // Automatically converted to double 16
Image of page 16
Problem 1: Incorrect Parameter Types 17 Node b = new Node(); TreeNode r = new TreeNode(); BTreeNode s = new BTreeNode(); Lunch<Node, TreeNode, BTreeNode> l = new
Image of page 17

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 18
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern