AP Computer Science A

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/102

flashcard set

Earn XP

Description and Tags

AP Computer Science A Exam - Flashcards to help study and learn material.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

103 Terms

1
New cards

What are the System.out.print and System.out.println methods used for?

To send output for display on the console

2
New cards

What is the difference between System.out.print and System.out.println?

The println method moves the cursor to a new line after displaying the given data, while the print method does not.

3
New cards

What is a comment in Java?

Any text in a source code file that is marked to not be executed by the computer

4
New cards

How are single line comments denoted in Java?

//

5
New cards

How are multiline comments demarcated in Java?

/* and */

6
New cards

What are the three primitive types used in AP Computer Science A?

int, double, boolean

7
New cards

What are literals?

Representations in code of exact values

8
New cards

What are the arithmetic operators in Java?

+, -, *, /, %

9
New cards

According to precedence rules, which operators are evaluated first?

*, /, %

10
New cards

According to precedence rules, which operators are evaluated second?

+, -

11
New cards

How are operators within the same group evaluated?

They are evaluated in the order in which they appear in the expression

12
New cards

What are parentheses used for?

To override the default precedence rules

13
New cards

When an arithmetic operation involves two int values, what is the result?

The result is an int, truncating any non-integer part

14
New cards

If an operation involves at least one double value, what is the result?

The result will be a double, behaving as expected mathematically

15
New cards

What is a variable?

A name that is associated with a piece of computer memory that stores a value

16
New cards

What must be declared as being of a certain type?

Every variable that is used in a program

17
New cards

What does A variable declaration statement consists of?

A type followed by a name.

18
New cards

What does an assignment statement have?

A variable on the left side of an equal sign, and an expression on the right side

19
New cards

How can a variable be declared to refer to a value that will never change?

Using the final keyword

20
New cards

If a variable that is declared with final, what error does it cause if you try to change it again?

A compiler error

21
New cards

What is an example of a compound operator?

x += 3

22
New cards

What is an example of an increment operator?

x++

23
New cards

What is an example of a decrement operator?

x--

24
New cards

What casting operators can be used to create temporary values converted to another type?

(int) and (double)

25
New cards

What does casting a double to an int result in?

Truncation

26
New cards

In some cases, what happens to int values?

They are automatically cast to double value

27
New cards

What is the special value reserved for reference variables that do not contain a reference to any actual object?

null

28
New cards

How is interaction with objects primarily done?

Calling their methods

29
New cards

What does it mean when methods can be overloaded?

Multiple methods with the same name that may exist in a class, as long as their signatures are different

30
New cards

When a method is called, what happens to the execution of the program?

The execution of the program is interrupted, and control is transferred to the method

31
New cards

How can void methods only be called?

As standalone statements, rather than as part of an expression

32
New cards

How is a method called?

The dot operator between the name of the object and the name of the method, followed by a list of parameters in parentheses

33
New cards

What will happen if a method is called on a null value?

A NullPointerException to be thrown

34
New cards

When a method is not void, what happens to the method call expression?

It can be used as part of an expression in place of any value of the specified type

35
New cards

How can a single character (as a string) at index n be retrieved?

By calling substring(n, n+1)

36
New cards

Is a String immutable?

Strings are immutable and they have no mutator methods

37
New cards

What wrapper classes does Java provide?

Integer and Double

38
New cards

What features does the Java compiler have that automatically convert between these wrapper classes and the corresponding primitive types?

Autoboxing and unboxing

39
New cards

What is a static method?

A method that is called using the name of the class to which it belongs, rather than an object.

40
New cards

What class is an example of a class that contains only static methods?

Math

41
New cards

What is De Morgan's Laws used for?

To transform Boolean expressions into equivalent ones

42
New cards

What are the operators used to check whether a reference variable is null?

==(equal) and !=(not equal)

43
New cards

How is the equals method called?

Using the dot operator between the name of the object and the equals method, followed by a list of parameters in parentheses

44
New cards

What is used when a program needs to make decisions based on its current state?

Control flow statements

45
New cards

What does an if statement do?

Allows the program to either execute or skip a section of code based on whether a Boolean expression is true or false.

46
New cards

What does an if followed by one or more else if clauses do?

Multiple possibilities

47
New cards

What statement allows a code block to repeat as long as a condition is true?

The while statement

48
New cards

What will happen if the condition in a while loop never becomes false?

The program will be executed infinitely

49
New cards

What does a for loop use?

A variable to count the iterations of a loop

50
New cards

When a loop is used in the body of another loop, what is it referred to as?

Nested loop

51
New cards

What are the basic components of writing classes?

Instance variables, constructors, and methods

52
New cards

What should the visibility be for instance variables?

Private

53
New cards

What should the visibility be for constructors?

Public

54
New cards

What should the visibility be for methods?

Public or private

55
New cards

What is the purpose of a constructor?

To set up an object with some initial state, and generally consists of assigning values to the instance variables

56
New cards

What is a default constructor?

A constructor that does not have any parameters

57
New cards

If a constructor does not explicitly set an instance variable, what happens to the variable?

The variable will automatically be given a default value

58
New cards

What must be true immediately prior to a method being called?

Precondition

59
New cards

What is guaranteed to be true immediately after the execution of the method?

Post condition

60
New cards

What is a method?

A block of code that exists within a class and has access to the instance variables

61
New cards

What values can visibility be when writing a method?

public or private

62
New cards

What is it called when it retrieves and returns data associated with the class but does not modify?

Accessor

63
New cards

To return a value from a method, what statement should be used?

the statement return expression;

64
New cards

What does a return statement do?

Will immediately terminate the execution of the method

65
New cards

What kind of method changes the state of the object in question by modifying one or more of its instance variables?

Mutator

66
New cards

What method implemented in many classes returns a string?

The toString method

67
New cards

What is the parameter as declared within a method header referred?

Formal parameter

68
New cards

What is the value passed in when the method is called?

Actual Parameter

69
New cards

In Java, how are parameters always passed?

Passed by value

70
New cards

What refers to the code within which it is accessible?

Scope

71
New cards

What is declared within the body of a constructor or method?

A local variable

72
New cards

What do you call the type of method that merely retrieves and returns, but does not modify?

Accessor

73
New cards

Where are instance variables declared in a class accessible?

Throughout the entire class

74
New cards

Within a constructor or non-static method, what additional variable is always available?

this

75
New cards

What are associated with a class, rather than with instances of the class?

Static variables and methods

76
New cards

What is an array?

An object that allows a single variable to refer to multiple values of a particular type

77
New cards

What keyword is used to create an array?

new

78
New cards

When an array is created without this, all its elements are automatically initialized with

Default values

79
New cards

What does zero represent?

Minimum valid index in every array

80
New cards

What does array length -1 represent?

Maximum valid index in every array

81
New cards

Use of an index outside of the valid range will cause what error?

ArrayIndexOutOfBoundsException to be thrown

82
New cards

What refers to systematically accessing all elements within it?

Traversing

83
New cards

What type of loop is useful for traversing arrays?

Enhanced for loop

84
New cards

What stores multiple elements of the same type, but differs with arrays as its size is not set at creation and can change dynamically?

Arraylist

85
New cards

What is a standard and universal algorithm used in Arraylist?

Sequential search, or linear search

86
New cards

What is an array of arrays, often thought of as a rectangular array of values, with rows and columns?

2D Array

87
New cards

What represents shared attributes so that code can be shared and reused between the classes?

Inheritance

88
New cards

How many subclasses can a superclass have?

A subclass can only have a single superclass, but a superclass can have many subclasses.

89
New cards

Are constructors inherited from a superclass?

Constructors are not inherited from a superclass

90
New cards

Within a subclass constructor, the super keyword can be used to _ ?

call a superclass constructor

91
New cards

What does the call to the super class constructor need?

The call to a superclass constructor must be the first line in a subclass constructor

92
New cards

What does a subclass inherit?

Inherited all the attributes and behaviors of its superclass, it cannot access private variables or methods from the superclass

93
New cards

What should a string 0 or 1 equal to in a reverse string technique?

Return 1

94
New cards

What is recursion?

A programming technique where a function calls itself in order to solve a problem.

95
New cards

What is a base case in recursion?

The condition that stops the recursive calls and provides a direct solution to the smallest subproblem.

96
New cards

What is a recursive step?

The part of a recursive function where the function calls itself with a modified input, moving towards the base case.

97
New cards

What is the importance of a base case in recursion?

Without a base case, a recursive function would call itself infinitely, leading to a stack overflow error.

98
New cards

What is sorting?

The process of arranging elements in a collection (e.g., array, list) in a specific order (e.g., ascending or descending).

99
New cards

What is a common sorting algorithm that works by repeatedly stepping through the list, compares adjacent elements, and swaps them if they are in the wrong order?

Bubble Sort

100
New cards

What is a sorting algorithm that divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves?

Merge Sort