Test 2 Review Checklist
These are the new topics covered since test 1.
Methods (i.e. functions)
Method Basics
- Know what a method is
- Reasons for writing methods (divide-and-conquer, reusability)
- Perspective: builder vs. caller
Using Methods
- Know how to call a method
- syntax
- passing arguments
- using the returned value
- Understand how they are like mathematical functions
- Predefined methods
- methods in libraries
- static vs. instance -- know the difference in the call syntax
Building Methods
- Prototype -- name, return type, parameter list
- Know the format
- Know what to specify in the parameter list
- Header includes modifiers (like public and static), as well as
prototype
- Definition -- header, along with method body
- the keyword return -- returning values from methods
- using the formal parameters in the method
- Scope (and how it relates to methods)
- Meaning of scope
- Variables local to function blocks
- Variables local to internal blocks (like loop bodies)
- Scope of method parameters
- void as a return type
- Empty parameter lists
- Method overloading - methods with same name and different
parameter lists
Strings
-
Know how to construct a String object
-
Know the common String methods: length(), concat(), equals(),
compareTo(), charAt(), substring(), trim(), toLowerCase(),
toUpperCase(), replace(), valueOf(), and the concatenation operator
+
-
Know the difference between String and
StringBuilder
- Know the common StringBuilder methods: append(), insert(),
delete(), along with common methods that work the same as
for String (charAt(), length() for example), and know
how to construct one
Arrays
-
Understand arrays, this includes multi-dimensional arrays
- Know how to declare an array variable, and then create the array
with the new operator
int[] array1 = new int[size];
-
Understand how array indexing is used, this includes
multi-dimensional arrays
Remember array indexing starts at zero and NOT
one.
given
array =
{
{1, 2, 3, 4},
{5, 6, 7},
{8}
}
Then array[1][2]
is equal to 7.
-
Know that the length of an array (say named
array
) can be
found by using array.length
-
Know that the reference (name) of an array can point to any array
of that type
(two array references can point to the
same array)
-
Understand all the ways to declare an array variable. All the
following
are the same and are legal
(the first is the preferred way):
int[][][] thingy;
int[][] thingy[];
int[] thingy[][];
int thingy[][][];
-
Understand how to declare, create, and initialize an array all at
once
int[] bubba = {2, 5, -56};
- Know how to pass arrays in and out of methods
- Know how to interpret and how to write an enhanced for-loop,
especially for use with arrays
- Understand how to interpret and how to write a variable-length
parameter list on a method. Know when it is legal to do so
Some practice array algorithms to try (coding practice)
(You should be able to do these and other similar array algorithms)
- Compute and print the sum (product, average) of the elements of a
numerical array.
- A method that returns the maximum element of an array
- A method that prints all array elements that are between two given
values (parameters)
- A method that counts up all the even numbers in an array
- A method that returns an array that contains all odd elements from
an original array (incoming parameter)
Classes and Objects
- Objects and classes and the relationship between them
- Understand how to declare an object reference variable and
then create the object with
new
, along with how
to invoke the chosen constructor
- Understand how objects are passed in and out of methods
- Constructors:
- Know what a constructor is for
- Know how to identify a constructor in a class definition (i.e.
the constructor has the same name as the class and no return
type)
- Know how to invoke a constructor (when building an object with
new
- The modifiers public and private
- Accessor and mutator methods
- The special toString() method
- The static modifier, and the difference between
static variables and methods vs. instance variables and methods, as
well as which variables can be accessed from which methods
- The keyword this
- Class scope vs. local scope (like in a method)
- Arrays of objects (array of reference variables, each can attach to
an object)
Programming hints
Here is a sample programming problem similar to how I might ask a
question on the test.
Sample Exercise
Write a method that will return the number of elements in an array
that are greater than a given number.
Given this sample main
method:
public static void main(String[] args)
{
int[] array = {14, 6, 3, 2, 8, 5};
System.out.println("Given the following: array = ");
printArray(array);
System.out.println();
System.out.println("The number of elements greater than 5 is " +
greater(array, 5));
}
The output is:
Given the following: array = {14, 6, 3, 2, 8, 5}
The number of elements greater than 5 is 3
Write the method called greater