AP CSA Unit 4.1-4.7

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/37

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:11 AM on 4/29/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

38 Terms

1
New cards

Algorithmic bias

describes systemic and repeated errors in a program that create unfair outcomes for a specific group of users. 

2
New cards

data set

a collection of specific pieces of information or data.

  • For example, the following table is a data set that keeps track of information about students.

  • Data can be represented in a diagram by using a chart or table. Here it is shown as a spreadsheet table with columns for the first name, last name, email, and GPA.

<p>a collection of specific pieces of information or data. </p><ul><li><p>For example, the following table is a data set that keeps track of information about students. </p></li></ul><ul><li><p>Data can be represented in a diagram by using a chart or table. Here it is shown as a spreadsheet table with columns for the first name, last name, email, and GPA.</p></li></ul><p></p>
3
New cards

array

a block of memory that stores a collection of data items (elements) of the same type under one name. Arrays are useful whenever you have many elements of data of the same type that you want to keep track of, but you don’t need to name each one. Instead you use the array name and a number (called an index) for the position of an item in the array.

4
New cards

index

a number that indicates the position of an item in a list, starting at 0

5
New cards

Declaring and Creating an Array

When we declare a variable, we specify its type and then the variable name. To make a variable into an array, we put square brackets after the data type. For example, int[] scores means we have an array called scores that contains int values.

6
New cards

How to create an array

use the new keyword with the type and the size of the array (the number of elements it can hold). This will actually create the array in memory.

  • You can do the declaration and the creation all in one step, see the String array names below. The size of an array is set at the time of creation and cannot be changed after that.

<p><span>use the </span><strong>new</strong><span> keyword with the type and the size of the array (the number of elements it can hold). This will actually create the array in memory. </span></p><ul><li><p><span>You can do the declaration and the creation all in one step, see the String array </span><code>names</code><span> below. The size of an array is set at the time of creation and cannot be changed after that.</span></p></li></ul><p></p>
7
New cards

length

how many elements an array can store

8
New cards

dot-notation

Used to access the instance variable, for example arrayName.length

9
New cards

first element in an array

.length - 1

(index 0)

10
New cards

indexed array variable

the array name and the index inside of square bracket [ ]

11
New cards

Array Index Out Of Bounds Exception.

Using an index value outside of 0 - (length-1) will result in this

12
New cards

i

Used in loops to traverse an array. In challenging AP problems, you will see mathematical expressions inside the square brackets ([]).

13
New cards

array[i-1]

refers to the previous element right before the ith element in array

14
New cards

array[i+1]

refers to the next element after the ith element.

15
New cards

Traversing

Doing this to an array means visiting each element of the array. We can use a loop to visit each element of an array and perform some operation on it. This is a common operation when working with arrays.

16
New cards

iteration

when repetition statements are used to access all or an ordered sequence of elements in an array.

  • We can traverse an array with an indexed for loop or while loop, accessing the elements using an index variable.

  • Just start the index at 0 and loop while the index is less than the length of the array. Note that the variable i (short for index) is often used in loops as the loop counter variable and is used here to access each element of an array with its index.

  • Since this is a simple counter-controlled loop, for loops are used more often than while loops for array traversals.

<p> when repetition statements are used to access all or an ordered sequence of elements in an array. </p><ul><li><p>We can traverse an array with an indexed <code>for</code> loop or <code>while</code> loop, accessing the elements using an index variable.</p></li><li><p>Just start the index at <strong>0</strong> and loop while the index is less than the <strong>length</strong> of the array. Note that the variable <strong>i</strong> (short for index) is often used in loops as the loop counter variable and is used here to access each element of an array with its index. </p></li><li><p>Since this is a simple counter-controlled loop, <code>for</code> loops are used more often than <code>while</code> loops for array traversals.</p></li></ul><p></p>
17
New cards

Off by one errors

These errors are easy to make when traversing an array, resulting in an ArrayIndexOutOfBoundsException being thrown.

  • In for and while loops, make sure the index for an array starts at 0 and end at the number of elements − 1.

18
New cards

enhanced for loop (for-each loop)

Can be used to loop through an array without using an index variable. Loops through ALL the Values WITHOUT CHANGING THEIR VALUES

To set up a for-each loop, use for (type variable : arrayname) where the type is the type for elements in the array, and read it as “for each variable value in arrayname”.

  • cannot modify the array elements.

<p>Can be used to loop through an array without using an index variable. Loops through ALL the Values WITHOUT CHANGING THEIR VALUES</p><p>To set up a for-each loop, use <strong>for (type variable : arrayname)</strong> where the type is the type for elements in the array, and read it as “for each variable value in arrayname”.</p><ul><li><p><span>cannot modify the array elements.</span><br></p></li></ul><p></p>
19
New cards

When you should not use a for each loop

Only use for-each loops when you want to loop through all the values in an array without changing their values.

  • Do not use for each loops if you need the index.

  • Do not use for each loops if you need to change the values in the array.

  • Do not use for each loops if you want to loop through only part of an array or in a different order.

20
New cards

accumulator pattern

an algorithm that iterates through a set of values using a loop and updates an accumulator variable with those values, for example to compute a sum or average of a set of values. The accumulator pattern has 4 steps:

  1. Initialize the accumulator variable before the loop.

  2. Loop through the values.

  3. Update the accumulator variable inside the loop.

  4. Print or use the accumulated value when the loop is done.

21
New cards

file

storage for data that persists when the program is not running. The data in a file can be retrieved during program execution.

  • A file can be connected to the program using the File and Scanner classes. These classes must be imported in from libraries; the Scanner class is in the java.util package and File is in the java.io package ( io stands for input/output).

  • When using the File class, it is required to indicate what to do if the file with the provided name cannot be opened. One way to accomplish this is to add throws IOException to the header of the method that uses the file. If the file name is invalid, the program will terminate.

22
New cards

While loop

Usually used to read in a file with multiple lines.

  • The loop can use the method hasNext as the loop condition to detect if the file still contains elements to read. A loop with this condition will terminate when there are no more lines to read in the file. After the loop is finished reading the data, the close method from Scanner should be called to close the file.

<p>Usually used to read in a file with multiple lines.</p><ul><li><p> The loop can use the method <code>hasNext</code> as the loop condition to detect if the file still contains elements to read. A loop with this condition will terminate when there are no more lines to read in the file. After the loop is finished reading the data, the <code>close</code> method from Scanner should be called to close the file.</p></li></ul><p></p>
23
New cards

Split string delimeter

splits a string into an array of substrings based on a specified delimiter which is a character like a comma or a space that separates the units of data. This method returns a String array where each element in the array represents a field of data from the line.

24
New cards

java.io package

(AP 4.6.A.5) The File and IOException classes are part of this package. An import statement must be used to make these classes available for use in the program.


25
New cards

Scanner(File f)

the Scanner constructor that accepts a File for reading.

26
New cards

int nextInt

returns the next int read from the file or input source. If the next int does not exist, it will result in an InputMismatchException. Note that this method does not read the end of the line, so the next call to nextLine() will return the rest of the line which will be empty.

27
New cards

double nextDouble ()

returns the next double read from the file or input source. If the next double does not exist, it will result in an InputMismatchException.

28
New cards

boolean nextBoolean ()

returns the next Boolean read from the file or input source. If the next boolean does not exist, it will result in an InputMismatchException.

29
New cards

String nextLine ()

String nextLine() returns the next line of text up until the end of the line as a String read from the file or input source; returns the empty string if called immediately after another Scanner method like nextInt that is reading from the file or input source;returns null if there is no next line.


30
New cards

String next()

eturns the next String up until a white space read from the file or input source.

31
New cards

boolean hasNext()

returns true if there is a next item to read in the file or input source; false otherwise.

32
New cards

Void close ()

closes the input stream.

33
New cards

Wrapper class

A class that wraps (encloses) around a primitive data type and gives it an object appearance.

  • The wrapper classes are part of the java.lang package, which is imported by default into all Java programs.

  • The Integer class and Double class are wrapper classes that create objects from primitive types of int and double respectively.

<p>A class that wraps (encloses) around a primitive data type and gives it an object appearance. </p><ul><li><p>The wrapper classes are part of the java.lang package, which is imported by default into all Java programs. </p></li><li><p>The Integer class and Double class are wrapper classes that create objects from primitive types of int and double respectively.</p></li></ul><p></p>
34
New cards

Autoboxing

The automatic conversion that the Java compiler makes between primitive types and their corresponding object wrapper classes. This includes converting an int to an Integer and a double to a Double.

  • The Java compiler applies autoboxing when a primitive value is passed as a parameter to a method that expects an object of the corresponding wrapper class or assigned to a variable of the corresponding wrapper class. Here’s an example of autoboxing.

<p>The automatic conversion that the Java compiler makes between primitive types and their corresponding object wrapper classes. This includes converting an int to an Integer and a double to a Double.</p><ul><li><p><span>The Java compiler applies autoboxing when a primitive value is passed as a parameter to a method that expects an object of the corresponding wrapper class or assigned to a variable of the corresponding wrapper class. Here’s an example of autoboxing.</span></p></li></ul><p></p>
35
New cards

Unboxing

The automatic conversion that the Java compiler makes from the wrapper class to the primitive type. This includes converting an Integer to an int and a Double to a double.

  • The Java compiler applies unboxing when a wrapper class object is passed as a parameter to a method that expects a value of the corresponding primitive type or assigned to a variable of the corresponding primitive type.

<p>The automatic conversion that the Java compiler makes from the wrapper class to the primitive type. This includes converting an Integer to an int and a Double to a double. </p><ul><li><p>The Java compiler applies unboxing when a wrapper class object is passed as a parameter to a method that expects a value of the corresponding primitive type or assigned to a variable of the corresponding primitive type.</p></li></ul><p></p>
36
New cards

Underflow

Java will return the maximum integer value if you try to subtract one from the minimum value

<p><span>Java will return the maximum integer value if you try to subtract one from the minimum value</span></p><p></p>
37
New cards

Overflow

Java will return the minimum integer value if you try to add one to the maximum.

<p><span>Java will return the minimum integer value if you try to add one to the maximum.</span></p><p></p>
38
New cards

Parse methods

can be used to convert strings to numbers.

They are often used with the Scanner class to convert input which is read in as a String into an int or double so that you can create arithmetic expressions (do math) or create logical conditions that test the values against other numbers using relational operators like < and >

<p><span>can be used to convert strings to numbers. </span></p><p></p><p><span>They are often used with the </span><code>Scanner</code><span> class to convert input which is read in as a </span><code>String</code><span> into an </span><code>int</code><span> or </span><code>double</code><span> so that you can create arithmetic expressions (do math) or create logical conditions that test the values against other numbers using relational operators like </span><code>&lt;</code><span> and </span><code>&gt;</code></p>