1302 test1

  1. What is an object and what does it represent?
    A basic construct of OOP languages that model real world entities, and have unique identities, states, and behaviors
  2. How do we represent objects in java?
    Classes- blueprints that define data fields and methods that are used to create specific instances of an object
  3. How are state and behavior represented in a java class?
    • Data properties hold a value that represents the state
    • Actions that can be done to or with the object are done by methods which represent the behavior.
  4. What do we use to symbolically represent class designs? Not just in java
    UML- unified modeling language (describes data and behavior)
  5. Instance members
    Data attributes (instance variables) and methods (instance methods) defining the state and behavior of a single instance of an object
  6. How do we modify how objects are instantiated in java?
    Default constructors and convenience constructors (all can be overridden)
  7. What is a reference type and how do we use them?
    • Points to memory that holds referenced instance and it’s data. Reference variables should not point to the same object or it’s garbage
    • We use dot operator and instance members to set or modify values.
  8. How do we gain access to other classes in java that do not contain static methods?
    Create object and use dot operator to access instance members
  9. What are static members and when/why do we use them?
    • Class variables shared among all instances of a class.
    • Accessed with class Name.
    • Use when you want to update a value across all instances of an object
  10. How do we determine access to data members within a class?
    Visibility modifiers
  11. Why might we restrict access to data members within a class and how do we do it?
    • To set boundaries, prevent unwanted changes, error check, etc.
    • Can exclude accessors and mutators based on desired access of the data member
  12. What is encapsulating a data field?
    Protecting (hiding) an objects internal state by using modifiers instead of changing the class definition
  13. How do we protect static members?
    By excluding a set method and making a static get method only for viewing the private data field
  14. How to calculate sum of radius of all circles in an array?
    • for...
    • totalRadius += circleArray[i].getRadius();
  15. Create method that passes a object and returns copy
    • Public static Circle copyCircle(Circle c) {
    • Circle cp = new Circle(c.getRadius());
    • return cp; }
  16. For a class, what default values do the different data types get?
    Reference types get null, 0 for numeric, false for Boolean, \u0000 for char
  17. What are immutable objects and classes?
    A class or object that cannot be changed because there are no mutator or accessor methods to access private data members
  18. What is the scope of instance variables?
    The lifetime of instance variables is the same as lifetime of object
  19. How does the this keyword work and what does it provide access to?
    (My radius) it self references an object internally and provides access to the objects current internal state
  20. Why learn/use object oriented programming?
    We can bundle instance members which keeps associated information together... less data is passed around
  21. how do we express the associaton relationship classes can have?
    • Add labels directions and roles.
    • STUDENT—take—>COURSE<—teach—Faculty
    • Include the aggregated (has a) class within the aggregating class
    • *include multiplicity on UML
  22. What are different relationships classes can have?
    Association, aggregation, composition, inheritance
  23. How do we implement and deal with composed objects within java classes?
    • CompObj co = mainObj.getCompObjInst();
    • co.doStuff(); ie. Chaining
  24. how do we express the aggregation and composition relationship classes can have?
    • Aggregation is “has a”, diamond goes on the owner side.
    • If existence depends on owner, fill in diamond (composition)
  25. What is the point of learning/using OOP?
    Things like gui toolkits depend on the user knowing how to use objects and conventions to be effective
  26. Class abstraction and encapsulation and their benefits
    Allows us to hide away the implementation of certain things we want to represent as objects while being able to treat them like real world entities
  27. How do we create instances of objects?
    Using the new keyword
  28. Why is setting one object equal to another a bad idea (circle1 = circle 2)
    A COPY of a reference will lead to two references pointing to the same object, ultimately marking one for garbage collection
  29. How do we implement and deal with composed objects within java classes?
    • We retrieve the composed data members then touch the individual data members within the composed object.——— CompObj co = mainObj.getCompObjInst();
    • co.doStuff(); ie. Chaining
  30. What is aggregation and composition and how to represent them in UML and java?
    A
  31. Boxing and unboxing advantages
    Automatically converts a primitive type into an instance of its wrapper class by using the valueOf method. This is useful when java is expecting one but you give it the other. (ie. passing 42 to Integer i instead of new Integer(42))
  32. String, stringbuffer, and string builder class differences?
    • String- immutable strings,
    • StringBuilder- mutable strings,
    • StringBuffer- methods for updating strings
  33. Why use wrapper classes?
    So we can treat primitive like objects and use object based conveniences with them
  34. String class features?
    Matching, replacing tokens (“welcome”.replace(‘e’,‘A)), and splitting strings separated by punctuation or # into an array of strings. All of these can be used with a regex
  35. What is class abstraction and encapsulation and benefits?
    Allows us to hide away implementation of certain things we want to represent as objects so we can treat them as real world entities without needing to know internal implementations
  36. How to add a student in course class?
    students[numberOfStudents] = student; numberOfStudents++;
  37. How to display max value of integer class?
    Sysout(Integer.MAX_VALUE);
  38. Replacing with regex example?
    String s = “a+b$#c”.replaceAll(“[$+#]”,”NNN”); here the regex is specifying a pattern that matches $,+, or # and replacing it with NNN
  39. What is a regex
    A string that describes a pattern for matching a set of strings. Can use for matching replacing and splitting
  40. StringBuilder class
    Creates string objects that are mutable. If you do something to an object the string is changed permanently. Difference between string buffer is that it’s faster because it’s methods are unsynchronized
Author
timmymorin
ID
352573
Card Set
1302 test1
Description
Updated