An accessor method
__________________ accesses a class object without altering that object. An accessor returns some information about the object. Typically, but not always, an accessor name has the prefix “get”, as in getName, getAge, and so on.
An algorithm
____________ is a precise, step-by-step process to solve a problem or achieve a goal. Don’t write any code until your algorithm is completely clear to you. For example, an algorithm to fry and egg may start like this:
Place frying pan on stove.
Place pat of butter in pan.
Break egg into pan.
Oops! This algorithm won’t work. You omitted the step to turn on the stove.
An ArithmeticException
______________________ is a run-time error that is thrown when an attempt is made to divide an integer by 0.
An arithmetic operator
______________________ is an operator that can be applied to two numbers, namely, types int and double. Here are some examples of arithmetic operators in Java:
Operator | Meaning | Example |
---|---|---|
+ | addition | 3 + x |
- | subtraction | p - q |
* | multiplication | 6 * j |
/ | int division | 10/4 //returns 2, not 2.5 |
% | mod (remainder) | 6%3 //returns 0 |
An ArrayIndexOutOfBoundsException
_________________________________ is a run-time error that is thrown to indicate that the index for an array is illegal. An illegal index is outside the range of the array; that is, it is either negative or a value greater than or equal to the size of the array.
An assertion in Java
____________ is a precise statement about a program at any given point. The idea is that if an assertion is proved to be true, then the program is working correctly at that point. For example, if you write a method that sorts a random array, you might assert that the array is sorted after execution of the method.
The attributes of an object
___________________________ are the variables that hold information about that object. These are sometimes referred to as the data fields or instance variables of the object.
For example, some attributions of a Clown object may be footSize, wigColor, bagOfTricks, etc.
Autoboxing
__________ is the automatic conversion that the Java compiler makes between primitive types and their corresponding wrapper classes. This includes converting int to an Integer and a double to a Double.
Two examples:
Integer intOb = 8; //8 is autoboxed
ArrayList<Integer>list = new ArrayList<Integer>();
list.add(6); //6 is autoboxed
Unboxing
________ is the automatic conversion that the Java compiler makes between wrapper classes and their corresponding primitive types. This includes converting an Integer to an int and a Double to a double.
For example:
Integer intOb = 8, //8 is autoboxed
Int n = intOb; //intOb is unboxed, and n is assigned value 8
The average case of an algorithm
________________ is configuration of data that allows the algorithm to run in an amount of time that is the average of the best-case run time and the worst-case run time. In typical configurations of data (i.e., not specifically chosen data), the run time will be the average case. For example, suppose that a list of random integers is the be searched sequentially for a given key. In the average case, the key will be found somewhere near the middle position.
A base case in a recursive method
___________ is the termination condition that causes a recursive method to end. For example:
if (n == 1) //base case
return;
The behaviors of an object in Java
__________________________ are given by its methods. For example, the behaviors of a Dog object may include bark, eat, drool, wagTail, and so on.
The best case of an algorithm
_____________ is a configuration of data that allows the algorithm to run in the least amount of time. For example, suppose that a list of random integers is to be searched for a given key. In the best case, the key will be found in the first position examined.
A Boolean expression
____________________ is a Java expression that has one of two values: true or false. Boolean expressions are used in conditional statements, such as if, if … else, and while loops.
For example, in the statement if ( x == y) …
x == y is a Boolean expression.
Other examples of Boolean expressions: x < 4, y 1= 10, etc.
Bottom-up development of a program
_____________________ starts with the writing and testing of the simplest classes in an object-oriented program. This is the opposite of top-down development, which starts with an overall summary of the whole program.
A class in Java
_______ is a software blueprint for implementing objects of a given type. The state of the object is maintained in its instance variables, and the behaviors of the object are describes by the methods of the class.
A client program for a class
________________ for any given class is an outside program that accesses the public methods of that class. For example, a LibraryBook class may be a client of the Scanner class, which can be imported from an outside package, and reads in data from the keyboard.
A compile-time error
____________________ occurs during compilation of a program, before execution starts. Some examples of actions in a program that cause compile-time errors:
using a variable that hasn’t been declared, invoking a method for an object that doesn’t have access to that method, using an incorrect parameter type, and so on
A composition relationship between classes
__________________________ is defined by a has-a relationship. For example, a Store has-a Item. Note that if two classes have a composition relationship, one of the classes contains an instance variable whose type is the other class.
A compound assignment operator
______________________________ provides a compact syntax for assigning the result of a binary arithmetic operation to a variable. Here are some examples:
Operator | Example | Meaning |
---|---|---|
+= | x += 3; | x = x + 3; |
-= | x -= 3; | x = x - 3; |
*= | x *= 3; | x = x * 3; |
/= | x /= 3; | x = x / 3; |
%= | x %= 3; | x = x % 3; |
The concatenation operator
The concatenation operator, +, operates on two strings, chaining them together. Thus, if at least one of left or right is a String operand, left + right produces a single string consisting of left followed by right.
A ConcurrentModificationException
_________________________________ is a run-time error that is thrown when an attempt is made to change the size of an ArrayList during traversal with an enhanced for loop. Therefore, an attempt to add or delete an element of the list during the traversal will trigger this error.
A constructor
_____________ is a block of code in a class used to create an object of the class. _____________ looks like a method but is not a method call. It has no return type and cannot be invoked by a direct method call. You can recognize a ___________ by its name—it must always be the same as the class. Like methods, ___________ can be overloaded.
The decrement operator
The decrement operator is —. When used with a variable, for example i— or —i, it decreases the variable by one. It is often used to keep decreasing a loop by one until a terminating condition is reached. For example:
int i = 8;
while (i > 5) { <doSomething>; i—; }
A driver class
______________ is a class with a main method that is used to test a program as it is being developed. This means that each class can be fully tested before it is incorporated as an object in a new class.
Dynamic binding
Dynamic binding (also known as late binding) is closely related to polymorphism. It is the process whereby the appropriate overridden method is called, not during compile time, but during run time for a particular object. For example, suppose a Student class has subclasses UnderGrad and GradStudent, each of which has an overridden computeGrade method. When a list of Student objects is processed, the correct computeGrade method will be invoked for each object during processing, depending on whether it is a GradStudent or an Undergrad.
Data encapsulation
___________________ is used in object-oriented programming. It is a mechanism for combining data (variables) and behaviors (methods) into a single unit (a class). In __________________, the variables of a class are hidden from other classes by declaring them private and can be accessed only through methods (getters and setters) of their current class.
An enhanced for loop
___________________ (also called a for-each loop) is a compact piece of code that iterates through all the elements of a collection. For example:
//print each element in arr, one per line
for (int value : arr)
{ System.out.printIn(value); }
An escape sequence in Java
__________________ is a character preceded by a backslash (\). It has a special meaning for the compiler. Some examples:
Escape Sequence | Meaning |
---|---|
\n | new line |
\” | double quote |
\\ | backslash |
An exception in Java
____________ is a run-time error that interrupts the normal flow of a program and provides a useful error message when the exception is thrown. Some examples of automatic (i.e., non-user-created) exceptions are ArrayIndexOutOfBoundException, ArithmeticException, NullPointerException, and so on.
A final variable
A final variable (also called an under-defined constant), identified by the keyword final, is a quantity whose value will not change once it has been assigned. In the following declaration, CLASS_SIZE is a final variable:
final int CLASS_SIZE = 25;
Floating-point division
Floating-point division a/b, is regular division if at least one of the operands a or b is a floating-point (real) number. Examples of floating-point division:
7.0/2 //returns 3.5
3/ (double)4 //returns 0.75
Beware of (double) (3/4), which returns 0.0, because the integer division 3/4 is computed first.
Formal parameters
Formal parameters are defined in the header of a method. Think of them as placeholders for the actual parameters or arguments that will be supplied to the method in a client program. For example, name and age are formal parameters in the method with this header:
public void setPerson (String name, int age)
An IllegalArgumentException
___________________________ is a run-time error that is thrown to indicate that a method has been invoked with an illegal or inappropriate argument. The programmer typically writes a test that screens in put for a method. If the input is “bad,” then an IllegalArgumentException is thrown to prevent the program from processing bad data.
An immutable object
__________________ is one that has no mutator methods. This means the object cannot be changed after it has been constructed. For example, a String object is immutable. (Note, however, that you can always create a new string that is a mutated form of an existing string.)
The increment operator
The increment operator is ++. When used with a variable, for example i++ or ++i, it increments the variable by one. It is often used to keep incrementing a loop variable by one until a terminating condition is reached. For example:
int i = 2;
while (i < 5) { <doSomething>; i++; }
An IndexOutOfBoundsException
____________________________ is a run-time error that is thrown to indicate that an index of some sort (such as to an ArrayList or a String) is out of range.
Information hiding
__________________ is the process of hiding the details of an object, usually by encapsulating the data and methods of the object in a class. This has the effect of decoupling the calling code from the internal workings of the object (i.e, changing the hidden parts does not lead to a change of the calling code).
Inheritance
___________ is a concept of object-oriented programming. It is a mechanism whereby a new class, called a subclass, is created from an existing class, called a superclass, by absorbing the state and behavior of the superclass and augmenting with features unique to the new class. We say that the subclass inherits characteristics of its superclass.