AP CSA - Fall Semester Review

studied byStudied by 19 people
0.0(0)
get a hint
hint

first line

1 / 87

Tags and Description

integer arithmetic, math methods, strings, tracing code, methods, writing code, arrays, arraylist, algorithms

88 Terms

1

first line

public class ProgramName
New cards
2

second line

public void main(String[] arg)
New cards
3

driver method

role of ‘main’ in second line

New cards
4

print line (code)

System.out.println(“”);
New cards
5

syntax error

case sensitive language; missing character (ex: ; ( { )

New cards
6

logic error

displays “hello” instead of “HELLO”; mathematical error by programmer

New cards
7

runtime error

occurs during execution; ex: divide by 0, out of bounds access of an array

New cards
8

identifiers

may include: letters, numbers, _, $; may not start w/ number; no spaces

New cards
9

source code

used in editor; MyName.java

New cards
10

byte code

used in compiler; MyName.class

New cards
11

machine code

used in interpret (JVM); code is translated + executed

New cards
12

compiler

checks for syntax errors; creates byte code, if there are no errors

New cards
13
print(“”)

displays argument

New cards
14
println(“”)

displays argument, then CRLF

New cards
15

CRLF

carriage return + line feed; new line

New cards
16
System.out

implies printing output

New cards
17
System.in

implies receiving user input

New cards
18
\n

escape sequence; new line

New cards
19
\\

escape sequence; prints one slash

New cards
20
\”

escape sequence; prints one double quote

New cards
21

integer

4 data types: byte, short, int, long; number with no decimals

New cards
22

real number

2 data types: float, double; number with decimals

New cards
23
boolean

1 data type; true or false

New cards
24
String

reference data type; saves reference to base16 memory address

New cards
25

concatenation

using ‘+’ to add strings

New cards
26
final

declare constant version of variable

New cards
27
+=

add by number after ‘=’

New cards
28
-=

subtract by number after ‘=’

New cards
29
/=

divide by number after ‘=’

New cards
30
*=

multiply by number after ‘=’

New cards
31
%=

divide by number after ‘=’; return remainder

New cards
32

integer division

division between two integers; returns no remainder or decimals

New cards
33

float division

division with at least one real number; returns decimals

New cards
34

modular division

division between two integers; returns remainder

New cards
35

binary shortcut

shortcut type; math sign then ‘=’ sign

New cards
36

unary shortcut

shortcut type; variable and two of math sign

New cards
37

x++ (or ++x)

adds one to x

New cards
38

x-- (or --x)

subtracts one from x

New cards
39

type casting

used when declaring variable; do not use twice

New cards
40
System.out.print(“hi” + 5 + 5);

hi55

New cards
41
System.out.print(“hi” + (5 + 5));

hi10

New cards
42

exponent

Math.pow(int x, int n);
New cards
43

square root

Math.sqrt(int x);
New cards
44

substring

.substring(int begIndex); 

.substring(int begIndex, int endIndex);
# does not include end Index
New cards
45

o Worl

(“Hello World”).substring(4, 10);
New cards
46
.length()

returns string length; starts with 1

New cards
47
.indexOf(String str)

returns position of first occurrence of str; returns -1 if not found

New cards
48
.charAt(int index)

returns character at a specified string

New cards
49

o

(“Hello World”).charAt(4);
New cards
50

if/else

executed if condition (placed in parentheses) is true; no semicolon at end; expects one line of following code, use { } for more

New cards
51

hi!

if (5 == 5)
return(“hi!”);
New cards
52
<

less than

New cards
53
<=

less than or equal to

New cards
54
>

greater than

New cards
55
>=

greater than or equal to

New cards
56
==

equal to, for logic

New cards
57
.equals(String str)

compares one String to another; returns boolean

New cards
58
!=

not equal to, for logic

New cards
59
for(int index = 0; condition; index++)

for loop; condition will return true while loop continues; index can be manipulated in various ways; standard form

New cards
60
for(int i = arrList.size() - 1; i >= 0; i --)

best for loop for iteration through arrayList which you will be removing items from

New cards
61
for(Object obj: arrList)

enhanced for loop; does not provide index or easily update item values

New cards
62

while loop

loop that iterates until condition is false; no provided index; condition must be in parentheses; expects one line of following code, use { } for more

New cards
63
Math.random()

provides a random double in [0.0, 1.0); to manipulate, add, divide, and Integer type casting

New cards
64
(int) (Math.random() * 11 + 4)

returns a number between 4 and 14 (inclusive)

New cards
65

method header

first line in method definition; includes visibility, return type, method name, and parameters

New cards
66

void

method header return type; no return

New cards
67

return type (method header)

specifies data type of returned values

New cards
68

parameters

data type needs to be specified (ex: (int age))

New cards
69
.length

returns length of an array

New cards
70
arr[i]

provides element at index i of array

New cards
71
int[] arr = new int[10];

initialize int array with default values

New cards
72
String[] arr = new String[] {“hello”, “world”};

initialize String array with pre-set values

New cards
73
null

default String value

New cards
74
0

default int value

New cards
75
false

default boolean value

New cards
76
.add(Object obj)

adds an element obj to the end of ArrayList

New cards
77
.add(int index, Object obj)

adds an element obj at index of ArrayList

New cards
78
.set(int index, Object obj)

changes element at index of ArrayList to obj

New cards
79
.remove(int index)

removes an element at index of ArrayList

New cards
80
.get(int index)

accesses element at index of ArrayList; used to print element

New cards
81
.size()

returns the size of ArrayList

New cards
82
ArrayList<Object> arrList = new ArrayList<Object>();

initialize empty ArrayList; can contain any object type

New cards
83

total algorithm

int x = 0;

for (int num : arrList)
x += num;

return x;
New cards
84

counting algorithm

int x = 0;

for (int num : arrList)
if (num == condition)
x+= 1;

return x;
New cards
85

search algorithm

for (int i = 0; i < arrList.size(); i++)

if (arrList.get(i) == condition)
return i;

return -1;
New cards
86

remove algorithm

for (int i = arrList.size() - 1; i >= 0; i--)
if (arrList.get(i) == condition)
arrList.remove(i);
New cards
87

smallest int algorithm

int x = nums.get(0);

for (int num : nums)
if (num < x)
x = num;

return x;
New cards
88

largest int algorithm

int x = nums.get(0);

for (int num : nums)
if (num > x)
x = num;

return x;
New cards

Explore top notes

note Note
studied byStudied by 19 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 69 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 20 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 36 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 144 people
Updated ... ago
5.0 Stars(3)
note Note
studied byStudied by 19 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 13 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 1759 people
Updated ... ago
4.7 Stars(11)

Explore top flashcards

flashcards Flashcard47 terms
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard42 terms
studied byStudied by 9 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard111 terms
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard196 terms
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard115 terms
studied byStudied by 13 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard137 terms
studied byStudied by 4 people
Updated ... ago
4.0 Stars(1)
flashcards Flashcard61 terms
studied byStudied by 24 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard39 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)