Exam 1 Review

Topics covered on the exam will include (but are not limited to) the following:

    • Java syntax
      • know where to place ; and how to use {}
    • Components of a Java class
      • data members
      • constructor (s)
      • methods
      • encapsulation - making data members private
    • Elements of a method
      • return type
      • parameter list
      • naming methods
      • method implementation
      • calling methods
      • pass by value and implications when passing references to objects
    • Variables
      • declaring variables
      • specifying variable type
      • primitive types versus reference types
      • NullPointerException
    • Statements and mathematical expressions
      • assignment versus comparison (= versus ==)
    • Object instantiation
      • use of the new operator
    • Conditionals (if statements)
      • use of >, <, =, !, &&, and ||
      • else-if and else
    • Iteration (for, while, do-while)
      • control variable
      • initialization, condition, and update
      • break and continue
    • Arrays
      • indices from 0 to N-1
      • ArrayIndexOutOfBoundsException
      • declaration and initialization of arrays
      • 2D arrays
      • iterating over arrays
      • insertion and deletion
    • Strings
      • compareTo method
      • split method
      • replace/replaceAll method

You are expected to have read all sections of the text list here.

Here are some sample exam questions:

    1. Explain the main parts of a method header.
    2. Write a method that takes as input an array of integers and returns the sum of all elements in the array.
    3. What is the output produced by the following code fragment:
    4. String s = "1|2|3|4";
    5. String[] theSplitString = s.split("2");
    6. System.out.print(theSplitString);
    7. A. [Ljava.lang.String;@8813f2
    8. B. Error – ArrayIndexOutOfBoundsException
    9. C. 1|
    10. D. 3 4
    11. True or False: All classes should provide getters and setters for all data members.
    12. Explain the difference between == and .equals.
    13. Identify at least two errors in the following class definition.
    14. public class Score {
    15. private String initials;
    16. private int score;
    17. public Score(String initials, int score) {
    18. this.initials = initials;
    19. score = score;
    20. }
    21. public String getScore() {
    22. return score;
    23. }
    24. }