AP CSA Unit 1

studied byStudied by 4 people
0.0(0)
Get a hint
Hint

An accessor method

1 / 38

39 Terms

1

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.

New cards
2

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.

New cards
3

An ArithmeticException

______________________ is a run-time error that is thrown when an attempt is made to divide an integer by 0.

New cards
4

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

New cards
5

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.

New cards
6

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.

New cards
7

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.

New cards
8

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

New cards
9

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

New cards
10

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.

New cards
11

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;

New cards
12

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.

New cards
13

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.

New cards
14

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, ifelse, 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.

New cards
15

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.

New cards
16

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.

New cards
17

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.

New cards
18

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

New cards
19

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.

New cards
20

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;

New cards
21

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.

New cards
22

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.

New cards
23

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.

New cards
24

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—; }

New cards
25

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.

New cards
26

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.

New cards
27

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.

New cards
28

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); }

New cards
29

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

New cards
30

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.

New cards
31

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;

New cards
32

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.

New cards
33

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)

New cards
34

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.

New cards
35

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.)

New cards
36

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++; }

New cards
37

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.

New cards
38

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).

New cards
39

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.

New cards

Explore top notes

note Note
studied byStudied by 17 people
... ago
5.0(1)
note Note
studied byStudied by 208 people
... ago
5.0(2)
note Note
studied byStudied by 13 people
... ago
5.0(1)
note Note
studied byStudied by 8 people
... ago
5.0(1)
note Note
studied byStudied by 6 people
... ago
5.0(1)
note Note
studied byStudied by 8 people
... ago
5.0(1)
note Note
studied byStudied by 36 people
... ago
5.0(1)
note Note
studied byStudied by 1806 people
... ago
4.7(6)

Explore top flashcards

flashcards Flashcard (105)
studied byStudied by 8 people
... ago
5.0(1)
flashcards Flashcard (119)
studied byStudied by 8 people
... ago
5.0(1)
flashcards Flashcard (21)
studied byStudied by 12 people
... ago
5.0(1)
flashcards Flashcard (121)
studied byStudied by 13 people
... ago
5.0(1)
flashcards Flashcard (23)
studied byStudied by 7 people
... ago
5.0(1)
flashcards Flashcard (77)
studied byStudied by 156 people
... ago
4.8(5)
flashcards Flashcard (48)
studied byStudied by 2 people
... ago
5.0(1)
flashcards Flashcard (159)
studied byStudied by 1982 people
... ago
4.5(13)
robot