APCSA important information and common mistakes

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

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:11 PM on 5/13/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

20 Terms

1
New cards

How can you determine if an equation results in a double?

If one value in an equation is a double (5.0 / 2 = 2.5), if the final variable is a double and equation is cast with “(double)”

2
New cards

How can you return the last digit(s) of a variable?

Use modulus by 10 for 1 digit, 100 for 2 digits and so on (n % 10 = last digit)

3
New cards

How do you apply DeMorgan’s law(!) on Boolean statements? (ie. distribute !(n < 3 && x == 5))

! in front of a boolean statement reverses operators, with && becoming || and vice versa(ie. !(n < 3 && x == 5) becomes (n >= 3 || x !=5)

4
New cards

What do you set instance variables to and why?(public, private, none)

Private is set, letting the instance variable only be accessible within its class. This is done for security reasons and prevents its alteration from other classes.

5
New cards

What are mutators and accessors?

Mutators are setter methods that set instance variables from their parameter. Accessors are getter methods that return instance variables.

6
New cards

What occurs when a class is called with a different number of parameters or different parameter types than the parameters in the constructors?

A compile-time error occurs.

7
New cards

How can you add more to strings?

By concatenating, which glues strings together with a + sign(ie. String1 + “ hello world”)

8
New cards

What are string Objects, and how do they compare to other strings?

String Objects result from classes(ie. String s1 = new String(“HELLO”), called with s1), they cannot use == to compare(will always print false), but require .equals() to compare.

9
New cards

What is the compareTo method?

It takes the lexicographical order(dictionary in which each character is assigned a number) and subtracts the lexicographical sum of all numbers of the second string from the first string.

10
New cards

What is the substring method?

returns a part of a string. String indexes start at 0 and go up to the length - 1. Substring methods require string.substring(Start index, end index + 1)

11
New cards

What are reference variables?

Reference variables are variables that require a class and can be accessed and changed through methods of that class(ie. String car1 = new String(“audi”), car1.getCar())

12
New cards

Where are variables created by a for loop(ie. int i) able to be found?

Only within the loop, outside of the loop will throw an error. This can be prevented by initializing the variable before the loop.

13
New cards

What are the two ways to declare an array?

You can either pre-populate it with:

variableType[] ([][] for 2d) name = {values separated by commas}

(ie. String[] array1 = {“A”, “B”, “C”})

Or you can make an empty array with:

variableType[] ([][] for 2d) name = new variableType[length of array](add [length of cols] for 2d)

Then, fill up the array: name[location](add a second [location] for 2D) = input. The default value for empty indices is labelled as null for string, 0 for int, 0.0 for double, false for bool

14
New cards

How can you change the size of an array?

It is not directly possible; instead, a new array is required with elements copied from the first array, then more elements need to be added.

15
New cards

How do you initialize an arraylist?

Arraylist<dataType> name = new Arraylist<dataType>();

ie. Arraylist<String> colors = new Arraylist<String>();

16
New cards

How do you read text files?

In a method:

File FILENAME = new File(“NAMEOFCSVFILE”);

Scanner input = new Scanner(FILENAME);

input.nextLine(); //skips header at top of textfile

while(input.hasNext()){

String info = input.nextLine;

System.out.println(info);

System.out.println();

}

input.close();

17
New cards

What needs to be added at the end of text file method headers?

throws IOException

18
New cards

What is the split class?

The split class returns an array where all elements of the instance del have been spliced out, and each element in the array is pieces of the string between the instance del

19
New cards

What is a wrapper class(how do you convert doubles/ints into strings)?

For doubles, Double.parseDouble(string s) is used, while for integers, Integer.parseInt(string s) is used

20
New cards

What order are the rows and cols in a 2d array, and how do you find their lengths?

[row][col]

For rows, array.length is used; for columns, array[0].length is used.