powerpoint 7.txt

Card Set Information

Author:
dimeng
ID:
302125
Filename:
powerpoint 7.txt
Updated:
2015-05-04 19:58:18
Tags:
diane cs140
Folders:
diane,cs140
Description:
diane cs140 powerpoint7
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user dimeng on FreezingBlue Flashcards. What would you like to do?


  1. The attributes of an object (that describe its state) are called ____________.
    instance variables
  2. In addition to attributes, classes can have _____________.
    methods
  3. What is the standard way of describing a class?
    A UML diagram.
  4. In the cookie cutter/cookie analogy, the class is the _________________ while the object is the ____________.
    cookie cutter (structure), cookie (instance)
  5. How many classes should be in a .java file?
    1
  6. Can classes compile without a program?
    Yes
  7. What is the minimum number of classes that should be in a program?
    1 - the file that holds the main method is also in a class
  8. An object is an ______________ of a class.
    instance
  9. How should you decide if a variable or a method that is part of a class should be public or private?
    Variables should be private. Methods should be private unless there is a compelling reason to make them public.
  10. What is the syntax for declaring a new instance of a class (an object)?
    className objectName = new className();
  11. When a new object is created, what happens in Java?
    The memory is allocated and the memory address of the object is assigned to the variable.
  12. What does the modifier "public" mean?
    It means that any other class can directly use or access the class, method, or instance variable by name.
  13. What does the modifier "private" mean?
    It means that no other class can directly use or access the class, method, or instance variable by name, but they can be accessed within the parent class.
  14. What can you do to make variables retreivable if they are private and you need to know access them outside of the parent class?
    You can make helper methods that return the value of private variables.
  15. Do NOT declare ___________ classes private. They will be unusable, as no one will be able to access them.
    outer
  16. What is a constructor?
    A constructor is a special type of method that is invoked when you create an object of a class with new.
  17. What does a constructor do?
    A constructor creates and initializes a new object whose address is then given back to the object.
  18. Constructors have ________ return type/value.
    no
  19. Constructors really return the ____________ of the newly created object.
    address
  20. Constructors must have the same ________ as the name of the class.
    name
  21. When a constructor is called, Java __________________ to all instance variables.
    assigns default values
  22. If you don't create a constructor, ____________________________.
    Java creates one for you
  23. If you create even one custom constructor, Java __________________________.
    won't do it for you anymore, and you must create a "default" type constructor
  24. Always make your own _______________ constructor (even if you don't plan to use it).
    standard
  25. What is this? What does it do?
    "this" is a reserved word in Java. Inside the definition of a method, it points to the object receiving the method call. It is usually optional, but good practice to use it.
  26. Constructors can/can not call other constructors.
    Can. It must be the first action taken by the constructor, though.
  27. Constructors are normally ________________________ class diagrams (UML).
    omitted from
  28. If other methods are called from the constructor, they should be _____________ to avoid unwanted actions.
    private
  29. As a matter of convention, constructors are __________________ in the class.
    grouped before all other methods
  30. Parameters are local to the ______________.
    method
  31. For Java's primitive data types, the data value is stored in the __________________________.
    memory location assigned to the variable
  32. For Java's class data types, the data value is ________________________________________.
    not stored in the variable, the memory address where the data will be stored is stored in the variable.
  33. If you want to know if the values stored in two string type variables are equal, how should you check that?
    Use the .equals operator, not =.
  34. You should always/never create your own equals() method for any classes you create.
    Always, even though java will create one for you.
  35. What are the three types of variables in Java (referring to scope)?
    • *local
    • *instance
    • *static
  36. Describe how static variables work in a class.
    When a class has a static variable, there is only one copy of the static variable; all objects in the class share the single copy of that variable.
  37. If static variables are not constants (not final), they should be ____________.
    private
  38. What does it tell you about a method if it is static?
    Static is used for methods that don't relate to objects (perform calculations, typically).
  39. What is the syntax for invoking a static method in a class?
    className.methodName(parameters, if needed)
  40. Can static methods refer to instance variables?
    No, because static methods cannot refer to objects.
  41. How can you call a non-static method from a static method?
    You must pass the object you need in the non-static method to the static method as an argument.
  42. What does Math.pow(x,y) do?
    Raises x to the y power.
  43. What does Math.abs(x) do?
    Returns the absolute value of x.
  44. What does Math.max(x,y) do?
    Returns the larger of x and y.
  45. What does Math.min(x,y) do?
    Returns the smaller of x and y.
  46. What does Math.random() do?
    Returns a random number between 0 (inclusive) and 1 (exclusive).
  47. What does Math.round(x) do?
    Rounds x to the nearest integer.
  48. What does Math.ceil(x) do?
    Returns the next largest integer (e.g., 5.4 -> 6).
  49. What does Math.floor(x) do?
    Returns the next smallest integer (e.g., 5.7 -> 5).
  50. What does Math.sqrt(x) do?
    Returns the square root of x.
  51. Passing an object to a method is to ________________________.
    pass the reference of the object (memory address).
  52. Primitive variable types are pass by ________________.
    value
  53. Because primitive variable types are pass-by-value, their value _________ be changed by methods.
    • cannot
    • +
    • Because objects passed as arguments are pass-by-reference, their value __________ be changed by methods.
    • can
  54. Can objects passed as arguments be replaced by the method they are passed to?
    No. The instance variables can be changed but the object cannot be replaced. (not sure I understand this)
  55. In a UML class diagram, how can you tell if ain instance variable, static variable, or method is to be public or private?
    + indicates public, - indicates private
  56. What is it called when methods in the same class share the same name? What can be said about their parameters?
    It is called overloading. Their parameter lists must differ in number, type, and/or order.
  57. Can you overload based on return type?
    No
  58. What is often overloaded in a class?
    The constructor method.
  59. Arrays can also hold ______________ just as they hold primitive types.
    objects (from classes)
  60. A package is a named collection of related _________________.
    classes
  61. The name of the package is the same as the name of the _______________.
    folder
  62. The package declaration must be the first _______________________ statement in a file. Its syntax is ________________.
    non-comment, package package_name;
  63. Describe the two principles of OO programming used in class design.
    • abstraction - use only the pertinent parts
    • encapsulation - hides the details of implementation from the user
  64. Class relationship diagrams show the general numeric relationship between classes (multiplicity). Give the three options for showing the multiplicity of the relationship between two classes.
    • * - unlimited number
    • m..n - range between m and n
    • m - exactly m
  65. What are associations in class relationship diagrams?
    Associations show the relationships between classes. e.g., in a school, students are associated with courses, and faculty are associated with courses. So, indirectly, faculty are associated with students.
  66. What are wrapper classes?
    Wrapper classes are objects that started as a primitive type. When you wrap them with a wrapper class, you have more methods available to use with them without restricting the functionality of the original wrapper class.
  67. Every _____________ type has a wrapper class.
    primitive
  68. What class must you import to use BigDecimal and BigInteger?
    • java.math.*
    • OR
    • java.math.BigDecimal and java.math.BigInteger

What would you like to do?

Home > Flashcards > Print Preview