1302 test 3

  1. What is an abstract class?
    A class that contains properties/behavior across related classes (inheritance), but it’s so general that it cannot create specific instances- no concrete implementations- constructors usually protected
  2. When would a subclass of an abstract super class be abstract?
    If a subclass of an abstract super class doesn’t implement all the methods
  3. What is an abstract method?
    Methods that represent commonality for all subclasses, but cannot be implemented at super class level (ie. getArea() getPerimeter() ), they do not force implementation
  4. Why should all non abstract subclasses implement any and all abstract methods?
    It guarantees availability for polymorphic calls through all subclasses.
  5. How do we create abstract classes and methods in java and UML?
    By using the abstract keyword and protected keyword since they are only intended to be used by subclasses. Name is italicized or with asterisk in uml, constructors have # sign before
  6. What is a concrete class and when would concrete superclass have abstract subclasses
    A class with implemented methods. Object class (concrete) has abstract subclass Shape (abstract).
  7. What is an interface?
    Not actually a class. Only contain constants and abstract methods. Specify behavior whether they’re related (inherited or aggregated) or not
  8. What is the purpose of an interface and how do you use one?
    • interface keyword and a name that ends in -able, -bile.
    • Specify property of an object
  9. How to implement comparable interface?
    • Import java.lang; Then (some class) implements interface Comparable.
    • Starts with generic type but you would put concrete type of the object you want to be comparable. Do not create your own comparable interface, just override abstract methods
  10. What is the difference between interfaces and abstract classes?
    Abstract is commonality between related classes, methods can be concrete, all types of data allowed. Interface is commonality between any class, methods must be abstract, only data is constants (public static final)
  11. What is a marker interface?
    An empty interface used to indicate that a class possesses certain properties
  12. What does cloneable do?
    Allows us to clone objects without making a clone that points to same memory location but rather has the same contents
  13. What is a shallow copy?
    Shallow- only copies primitive values, does not get contents of reference types. (== would be true but not .equals()) Clone method provides these by default.
  14. What considerations should we make when designing a class?
    It must describe a single entity, be designed for use and extension, default constructor and toString, encapsulation
  15. How to implement compareTo() method?
    Return positive integer, 0, or negative integer based on any calculation and/or order of your choosing. Uses @Override since all super classes implement Comparable.
  16. Why is comparable useful?
    • Once you implement a compareTo() method, you now have access to all sort functions.
    • All elements in an array are required to be instances of Comparable
  17. How to implement Cloneable interface?
    import java.lang; implement a class with cloneable which will mark it as cloneable, then @Override .clone() method.
  18. Differences between == and .equals() ?
    == references memory location, .equals() references contents of an object. Use .equals() with clone equality.
  19. How to implement clone() method?
    @Override. public visibilty, Object return type, throws CloneNotSupportedException. then implement a try (return super.clone()) catch. (Since it returns an Object you must cast the returned object to its original form)
  20. How to make a deep copy?
    Manually, when overriding clone(), get the reference variable in question (don’t forget to cast it), clone it, and set it to the copied variable. All this is after you’ve done a shallow copy
  21. Shallow copy example implementation
    House houseClone = (House)super.clone();
  22. Deep copy example implementation
    houseClone.setWhenBuilt( (java.util.Date)(getWhenBuilt().clone()));
  23. clone() method example
    • public Object clone() {
    • try {
    • shallow copy, manual deep copy, return variable
    • } catch (CloneNotSupportedException ex) {
    • return null;
    • }
  24. How do we create GUIs in java?
    By using JavaFX framework and using the Application abstract class. Launch method usually called by itself in main method
  25. What is a node in JavaFX?
    Visual component like buttons, shapes, pane, etc. placed by start() method, which go into panes, which go into scenes, which go into stages
  26. What are ways we can modify JavaFX nodes?
    By using get set methods like we would with any other object in java
  27. What does bind() do?
    Syncs values across two different objects (a target and source object). If a value in the bind(source) object changes, the target object changes automatically. bindBidirecrional() does this both ways. Can help auto center nodes and much more
  28. How can we arrange and group JavaFX nodes into reasonable facsimiles of interfaces?
  29. How to add “ok” button to previously created StackPane pane object
    pane.getChildren().add(new Button(“OK”));
  30. Methods to set outline and fill color of a circle object
    • circle.setStroke(Color.BLACK);
    • circle.setFill(Color.RED);
  31. What are the Font and Color classes in JavaFX?
  32. How can we arrange and group JavaFX nodes?
    Grouping and panes. (Panes within panes)
  33. How can we customize existing panes?
    Using inheritance to create a pre customized pane
  34. What is event driven programming?
    Programming executed upon activation of events generated by some external resource using the delegation model. Procedural programming just executes top to bottom
  35. Basic setup of GUI class
    Override start method(Stage primaryStage), add panes, instantiate scene with (pane, xWidth, yWidth), primaryStage.setScene(scene), primaryStage(show)
  36. Lambda expression setOnAction with calculate button?
    Create button called btCalculate.setOnAction(e -> calculateLoanPayment());
  37. Delegation model and example
    Handles events by assigning a listener to a source object. OkButtonHandler handler = new OkButtonHandler(); (add button to Hbox with get children) then assign button—-btCalculate.setOnAction(handler), then create a class that implements EventHandler and override handle(Action event e) method to handle it
  38. Inner class and how it’s used with JavaFX applications
    Handler classes used
  39. How to create anonymous inner classes and what are they used for?
    Creating a nameless class within the setOnAction( new EventHandler { public void handle(ActionEvent e) {}
  40. How to output calculation to application?
    Create a text field and setEditable(false), then .setText()
  41. How to get values from text fields?
    Create a text field and parse it- Double.parseDouble(textField.getText());
  42. Lambda expression syntax
    btAdd.setOnAction(e -> add());
Card Set
1302 test 3