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:
- Explain the main parts of a method header.
- Write a method that takes as input an array of integers and returns the sum of all elements in the array.
- What is the output produced by the following code fragment:
- String s = "1|2|3|4";
- String[] theSplitString = s.split("2");
- System.out.print(theSplitString);
- A. [Ljava.lang.String;@8813f2
- B. Error – ArrayIndexOutOfBoundsException
- C. 1|
- D. 3 4
- True or False: All classes should provide getters and setters for all data members.
- Explain the difference between == and .equals.
- Identify at least two errors in the following class definition.
- public class Score {
- private String initials;
- private int score;
- public Score(String initials, int score) {
- this.initials = initials;
- score = score;
- }
- public String getScore() {
- return score;
- }
- }