1 / 41

Final Review

James Atlas's final review for CISC370, covering Java basics, object-oriented programming, Java Collections framework, networking, and more. Features a fun "Family Feud" style game format with candy rewards. Includes bonus questions and helpful explanations.

Download Presentation

Final Review

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. Final Review James Atlas August 12, 2008

  2. “Family Feud” style • Each team gets a chance to pick an answer • The team with the highest ranked answer gets to try to guess the rest • 2 wrong answers and the other team can then “steal” the category • Each category winner gets candy! • Must be able to explain a little about the answer! And there are bonus questions… James Atlas - CISC370

  3. First, a list of topics • http://www.cis.udel.edu/~atlas/cisc370/finalprep.html • On the exam: • Java basics • Syntax, primitive types, control flow, naming conventions • Basic OOP syntax, object-oriented design • OOP in Java: Inheritance, Interfaces, Polymorphism • Advanced classes: inner classes and anonymous classes • Packages • Exceptions • Java Input/Output • Serialization/Cloning • Java Collections framework • The Swing toolkit • Network programming • Multithreaded programming • Software design patterns • XML James Atlas - CISC370

  4. James Atlas - CISC370

  5. What is Java? 50 int Object-oriented 30 float Cross-platform 15 long Large Library of Tools 5 boolean Programming Language (Sun) James Atlas - CISC370

  6. Name some components of the Java Virtual Machine 35 int Bytecode Interpreter 30 float Garbage Collector 25 long Dynamic Compiler 10 boolean Versions (native code for each platform) James Atlas - CISC370

  7. Name a Java primitive type int 20 int 17 float float long 15 long 15 boolean boolean double 10 double 10 byte byte 7 short short 6 char char James Atlas - CISC370

  8. Name a method/field access modifier 50 int public 25 float private 20 long protected 5 boolean package-private James Atlas - CISC370

  9. Name a different keyworded method/field modifier int 35 static 30 float final long 20 synchronized 10 boolean volatile 5 double transient James Atlas - CISC370

  10. How do you control a loop in Java? int 50 for 25 float while long 10 do-while 10 boolean break 5 double continue James Atlas - CISC370

  11. What Java constructs provide the basis for Object-oriented principles? 50 int Classes 25 float Interfaces 20 long Abstract Classes 5 boolean java.lang.Object/Instances James Atlas - CISC370

  12. BONUS: Every variable is passed-by-value in Java, how does this work? James Atlas - CISC370

  13. What components/properties make up a class definition? int 25 Fields/variables 20 float Constructors long 15 Methods 15 boolean Package 15 double Imports 10 byte Object hierarchy James Atlas - CISC370

  14. BONUS: What is overloading and how is it handled in Java? James Atlas - CISC370

  15. Name some common Interfaces related to the Java Collections Framework int 35 List 25 float Map long 20 Set 10 boolean Collection 5 double Comparable 5 byte Queue James Atlas - CISC370

  16. What keywords are used in Java Exception handling? 40 int catch 30 float try 20 long throws 10 boolean finally James Atlas - CISC370

  17. Name a Java I/O class or interface int 30 InputStream 28 float OutputStream long 17 FileInputStream/Out 15 boolean SocketInputStream/Out 6 double DataInputStream/Out 4 byte ObjectInputStream/Out James Atlas - CISC370

  18. BONUS: What design pattern does Java I/O follow? James Atlas - CISC370

  19. Name a way/reason to use an inner-class 30 int Hidden from other classes 26 float Convenient 24 long Implement interfaces on-the-fly 20 boolean Access the surrounding implementation James Atlas - CISC370

  20. Name a general software pattern (only ones we talked about in class) int 35 Factory 30 float Decorator long 25 MVC 6 boolean Command 4 double Observer/Event James Atlas - CISC370

  21. Name a component of the Java Swing framework int 30 Frame 25 float Container long 15 Layout boolean 10 Button 10 double Panel 6 byte Menu 4 short Event James Atlas - CISC370

  22. Name a component of the Java Network Programming model int 60 Socket 25 float ServerSocket long 15 Stream 5 boolean InetAddress 5 double DatagramPacket James Atlas - CISC370

  23. Name an activity that a Java program can perform on XML 35 int parse/read 30 float generate/write 25 long transform 10 boolean validate James Atlas - CISC370

  24. BONUS: Explain the difference between the SAX and DOM programming models James Atlas - CISC370

  25. The End! James Atlas - CISC370

  26. Object Destructors • In C++ (and many other OOP languages), classes have explicit destructor methods that run when an object is no longer used. • Java does not support destructors, as it provides automaticgarbage collection • Watches/waits until there are no references to an object • Reclaims the memory allocated for the object that is no longer used James Atlas - CISC370

  27. finalize() • Java supports a method named finalize(). • method is called before the garbage collector sweeps away the object and reclaims the memory • This method should not be used for reclaiming any resources • the timing when this method is called is not deterministic or consistent • only know it will run sometime before garbage collection James Atlas - CISC370

  28. Summary of Inheritance • Place common operations & fields in the superclass. • Remove repetitive code by modeling the “is-a” hierarchy • Move “common denominator” code up the inheritance chain • Protected fields are generally not a good idea. • Don’t use inheritance unless all inherited methods make sense • Use polymorphism. James Atlas - CISC370

  29. Abstract Classes • Some methods defined, others not defined • Classes in which not all methods are implemented are abstract classes. • public abstract class Animal • Blank methods are labeled with the abstract keyword also • public abstract void feed(); James Atlas - CISC370

  30. Abstract Classes • An abstract class cannot be instantiated • Subclass of an abstract class can only be instantiated if it overrides each of the abstract methods of its superclass and provides implementation • If subclass does not override all abstract methods, it is also abstract • Use abstract classes when you have a partial implementation James Atlas - CISC370

  31. Methods: An Alternate Ending • If a method throws an exception • it does not return anything • execution does not resume immediately following the method call (as it would if the method returns a normal value) • JVM’s exception-handling mechanism searches for an exception handler • Exception handler: error recovery code • runs to deal with a particular error condition. James Atlas - CISC370

  32. Streams • Java handles input/output using streams input stream: an object from which we can read a sequence of bytes Abstract class: InputStream James Atlas - CISC370

  33. Streams • Java handles input/output using streams output stream: an object to which we can write a sequence of bytes Abstract class: OutputStream James Atlas - CISC370

  34. Object Serialization • Serialization: process of converting an object to ordered data, to operate with streams • To allow a class of objects to be written and read with Object[Output/Input]Stream • the class must implement the Serializable interface • Serializable interface contains no methods • “Marker interface” • used to tag a class as able to be serialized • refers to the class’s ability to be converted into a single byte stream, which is then saved • All classes are inherently serializable • But you have to mark them as Serializable James Atlas - CISC370

  35. Object Serialization • When an object is written to a stream, it is written as a sequence of bytes. • Stores, in order • fingerprinting information that describes the class • instance fields and their values • a more complete class description. • The ability to convert an object from its “object” state to a byte stream state is what makes the direct writing and reading of objects possible James Atlas - CISC370

  36. Java-memory model (JMM) James Atlas - CISC370

  37. Java-memory model Rules • Atomicity • access/update to anything except long/double • Visibility • changes not always guaranteed visible • synchronization does • volatile variables • Thread.join() • Ordering • instructions in-thread are as-if-serial • out-of-thread no guarantee James Atlas - CISC370

  38. Thread Synchronization • In many multithreaded applications, more than one thread will need to access the same data • Can turn into a problem when two threads have access to the same object and then both modify the state of the object • Depending on the order of data access, the object can become corrupted • Known as a race condition James Atlas - CISC370

  39. Synchronized Methods • A method or block of code can be marked as atomic • Using keyword synchronized in method’s return type • After the section of code starts, the code is guaranteed to complete before another thread can enter another synchronized section belonging to that same object James Atlas - CISC370

  40. Synchronization Diagram James Atlas - CISC370

  41. Wait/Notify Mechanism Diagram James Atlas - CISC370

More Related