πŸ’» AP CSA Code Patterns Checklist (μ •μ—°μ΄μš©)

AP Computer Science A β€” Code Patterns Checklist

Practice 2 "Develop Code" 직접 μž‘μ„± + Practice 3 "Analyze Code" 트레이슀 β€” D-Day μ •λ…μš©

πŸ“Œ λΆ„λ₯˜: 🎨 직접 μž‘μ„± = FRQ Q1~Q4μ—μ„œ 학생이 μ§œμ•Ό ν•˜λŠ” μ½”λ“œ (Practice 2) πŸ“– 읽기·뢄석 = MCQμ—μ„œ trace 평가 (Practice 3, μ‹œν—˜μ˜ 37–53% 비쀑 μ΅œλ‹€)
πŸ“Œ 색상: 보라색 = AP CSA μ‹œκ·Έλ‹ˆμ²˜
πŸ“Œ 좜처: College Board AP CSA CED V.1 (Effective Fall 2025) Β· Course Framework Unit 1–4 + Java Quick Reference (Appendix)
πŸ“Œ μ‹œν—˜ ꡬ쑰 (CED V.1 Effective Fall 2025): 3μ‹œκ°„ β€” Section I Multiple-Choice 42λ¬Έν•­ / 90 minutes / 55% + Section II Free-Response 4λ¬Έν•­ (Q1 Methods and Control Structures 7점, Q2 Class Design 7점, Q3 Data Analysis with ArrayList 5점, Q4 2D Array 6점) / 90 minutes / 45% Β· 25점 만점.
πŸ“Œ 4 Units (MCQ 비쀑): Unit 1 Using Objects and Methods 15–25% Β· Unit 2 Selection and Iteration 25–35% Β· Unit 3 Class Creation 10–18% Β· Unit 4 Data Collections 30–40% (μ΅œλ‹€, 윀리·arrayΒ·ArrayListΒ·2DΒ·searchΒ·sortΒ·recursionΒ·inheritance 포함).
πŸ“Œ 5 Computational Thinking Practices: Practice 1 Design Code 2–10% Β· Practice 2 Develop Code 22–38% (FRQ 4λ¬Έν•­ λͺ¨λ‘) Β· Practice 3 Analyze Code 37–53% (MCQ μ΅œλ‹€) Β· Practice 4 Document Code and Computing Systems 10–15% Β· Practice 5 Use Computers Responsibly 2–10%.
πŸ“Œ 3 Task Verbs (CED p.148): Assume Β· Complete Β· Implement / Write.

🎨 직접 μž‘μ„± β€” Practice 2 "Develop Code"

FRQμ—μ„œ "Write the method" / "Write the class"κ°€ λ‚˜μ˜€λ©΄ μ•„λž˜ 17개 νŒ¨ν„΄ 쀑 ν•˜λ‚˜ μ΄μƒμ˜ 쑰합이닀. λ©”μ„œλ“œ 헀더(public/static/return type/λ§€κ°œλ³€μˆ˜) λˆ„λ½μ€ FRQμ—μ„œ 거의 μžλ™ -1점이닀.

1
Class μ„ μ–Έ + μƒμ„±μž (Constructor)
🎨 μž‘μ„± Unit 3 U3.3U3.4
μ ‘κ·Ό μ œμ–΄μžpublic class κ³ μ • (FRQ μ „μ œ). ν•„λ“œλŠ” 일반적으둜 private
μƒμ„±μž μ΄λ¦„ν΄λž˜μŠ€λͺ…κ³Ό μ •ν™•νžˆ 일치. return type μ—†μŒ
this ν‚€μ›Œλ“œλ§€κ°œλ³€μˆ˜μ™€ ν•„λ“œλͺ…이 κ°™μœΌλ©΄ this.field = field;
파일λͺ…ClassName.java β€” μ‹œν—˜μ—μ„œλŠ” 채점 μ•ˆ λ˜μ§€λ§Œ IDE/μ‹€μŠ΅μ—μ„œ 일치 ν•„μˆ˜
public class Student {
    private String name;
    private int grade;

    // constructor β€” same name as class, no return type
    public Student(String name, int grade) {
        this.name = name;
        this.grade = grade;
    }
}
  • public class + 클래슀λͺ… 일치
  • μƒμ„±μžλŠ” return type μ—†μŒ (void도 μ•ˆ 씀)
  • λ§€κ°œλ³€μˆ˜ == ν•„λ“œλͺ…일 λ•Œ this. ν•„μˆ˜
CED 원문: "A constructor is used to set the initial state of an object." (CED Topic 2.3) "this is a reference to the current object." (CED Topic 5.2)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: μƒμ„±μžμ— void λΆ™μ΄λŠ” μ‹€μˆ˜ β†’ 이건 일반 λ©”μ„œλ“œκ°€ 됨 (μƒμ„±μž X). this λˆ„λ½ μ‹œ λ§€κ°œλ³€μˆ˜κ°€ 자기 μžμ‹ μ—κ²Œ λŒ€μž…λΌ ν•„λ“œ μ΄ˆκΈ°ν™” μ‹€νŒ¨.
2
λ©”μ„œλ“œ μ‹œκ·Έλ‹ˆμ²˜ (Method Header)
🎨 μž‘μ„± Unit 1Β·3 U1.9U3.5
ꡬ쑰[modifier] [static?] returnType name(paramType param, ...)
void λ©”μ„œλ“œpublic void doSomething(int x) { ... } β€” return λ¬Έ 선택
λ°˜ν™˜ λ©”μ„œλ“œpublic int compute(int x, int y) { return x + y; } β€” λͺ¨λ“  κ²½λ‘œμ—μ„œ return ν•„μˆ˜
static λ©”μ„œλ“œpublic static int max(int a, int b) β€” 객체 없이 ClassName.max(...) 호좜
// instance method β€” needs object
public boolean isPassing() {
    return grade >= 60;
}

// static method β€” no object needed
public static int max(int a, int b) {
    if (a > b) return a;
    return b;
}
  • public ν‚€μ›Œλ“œ 빠뜨리면 컴파일 X (FRQ μžλ™ 감점)
  • return typeκ³Ό μ‹€μ œ λ°˜ν™˜ νƒ€μž… 일치 (cast ν•„μš”μ‹œ λͺ…μ‹œ)
  • voidκ°€ μ•„λ‹ˆλ©΄ λͺ¨λ“  λΆ„κΈ°μ—μ„œ return
CED 원문: "A method header includes the access modifier, the return type, the method name, and the parameter list." (CED Topic 2.7)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: if-else ν•œ μͺ½λ§Œ returnν•˜κ³  λ‹€λ₯Έ μͺ½ λˆ„λ½ β†’ "missing return statement" 컴파일 μ—λŸ¬. boolean도 true/false return λͺ…μ‹œ ν•„μˆ˜.
3
for 루프 (ν‘œμ€€ 인덱슀 루프)
🎨 μž‘μ„± Unit 2 U2.8
ꡬ쑰for (init; condition; update) { body }
ν‘œμ€€ ν˜•νƒœfor (int i = 0; i < n; i++) { ... }
μ—­λ°©ν–₯for (int i = n - 1; i >= 0; i--) { ... }
// sum 1 to n (inclusive)
int sum = 0;
for (int i = 1; i <= n; i++) {
    sum += i;
}
  • < vs <= μ •ν™•νžˆ (off-by-one 검증)
  • 인덱슀 λ³€μˆ˜ μ„ μ–Έ μœ„μΉ˜ (int i) β€” forλ¬Έ μ•ˆμ—μ„œ μ„ μ–Έ ꢌμž₯
  • update λˆ„λ½ μ‹œ λ¬΄ν•œ 루프
CED 원문: "The initialization, the boolean expression, and the increment statement together control how many times the loop body is executed." (CED Topic 4.2)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: λ°°μ—΄ λκΉŒμ§€ 돌릴 λ•Œ i <= arr.length β†’ AIOOBE. 항상 i < arr.length. i++ vs ++iλŠ” 단독 μ‚¬μš© μ‹œ 차이 μ—†μŒ (쑰심: 식 μ•ˆμ—μ„œλŠ” 닀름).
4
while 루프
🎨 μž‘μ„± Unit 2 U2.7
ꡬ쑰while (condition) { body; update; }
μ‚¬μš© μ‹œμ λ°˜λ³΅ 횟수 λ―Έμ • (μ‚¬μš©μž μž…λ ₯, 검색 μ’…λ£Œ λ“±)
update루프 μ•ˆμ—μ„œ λ°˜λ“œμ‹œ 쑰건을 λ³€ν™”μ‹œμΌœμ•Ό 함
// halve until below 1
double x = 100.0;
int count = 0;
while (x >= 1.0) {
    x = x / 2;
    count++;
}
  • 쑰건이 falseκ°€ λ˜λŠ” μ‹œμ  λͺ…ν™•νžˆ
  • update statement λˆ„λ½ = λ¬΄ν•œ 루프
  • μ΄ˆκΈ°ν™” λ³€μˆ˜λŠ” while λ°”κΉ₯에 μ„ μ–Έ
CED 원문: "A while loop repeats a block of code as long as a Boolean expression is true." (CED Topic 4.1)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: 쑰건은 λ§žμ·„λŠ”λ° update λˆ„λ½ β†’ λ¬΄ν•œ 루프. 항상 루프 λμ—μ„œ λ³€μˆ˜ λ³€ν™” 확인.
5
ν–₯μƒλœ for 루프 (for-each)
🎨 μž‘μ„± Unit 4 U4.4U4.9
ꡬ쑰for (Type x : collection) { ... }
λ°°μ—΄for (int x : arr) { sum += x; }
ArrayListfor (String s : list) { ... }
μ œμ•½μ›λ³Έ μ»¬λ ‰μ…˜ μˆ˜μ • λΆˆκ°€ (κ°’ 볡사). 인덱슀 μ‚¬μš© λΆˆκ°€
// sum array values β€” read-only iteration
int total = 0;
for (int n : nums) {
    total += n;
}
  • μ»¬λ ‰μ…˜ μ•ˆ element νƒ€μž…κ³Ό λ³€μˆ˜ νƒ€μž… 일치
  • μš”μ†Œ μˆ˜μ • / μ‚­μ œκ°€ ν•„μš”ν•˜λ©΄ ν‘œμ€€ for μ‚¬μš©
  • μΈλ±μŠ€κ°€ ν•„μš”ν•˜λ©΄ ν‘œμ€€ for μ‚¬μš©
CED 원문: "An enhanced for loop header includes a variable, called the enhanced for loop variable." "Assigning a new value to the enhanced for loop variable does not change the value stored in the array." (CED Topic 6.3)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: for-each μ•ˆμ—μ„œ x = 0; 해도 원본 배열은 λ³€ν•˜μ§€ μ•ŠμŒ. ArrayList의 .remove()λ₯Ό for-each μ•ˆμ—μ„œ ν˜ΈμΆœν•˜λ©΄ ConcurrentModificationException.
6
if / else if / else λΆ„κΈ°
🎨 μž‘μ„± Unit 2 U2.3U2.4 nested
ꡬ쑰if (cond1) { ... } else if (cond2) { ... } else { ... }
비ꡐ μ—°μ‚°μž== != < > <= >=
논리 μ—°μ‚°μž&& (AND) || (OR) ! (NOT) β€” 단좕평가
if (score >= 90) {
    grade = "A";
} else if (score >= 80) {
    grade = "B";
} else {
    grade = "F";
}
  • λŒ€μž… = vs 비ꡐ == ꡬ뢄
  • String/Object λΉ„κ΅λŠ” .equals() (μ ˆλŒ€ == X)
  • else if μˆœμ„œ β€” μœ„μ—μ„œλΆ€ν„° 평가
CED 원문: "Conditional statements interrupt the sequential execution of statements." (CED Topic 3.3)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: if (x = 5) 컴파일 μ—λŸ¬ (boolean μ•„λ‹˜). if (s == "A") β†’ μ°Έμ‘° 비ꡐ, λ¬Έμžμ—΄ 같아도 false κ°€λŠ₯.
7
λ°°μ—΄ 생성 + 순회 (1D Array)
🎨 μž‘μ„± Unit 4 U4.3U4.4
μ„ μ–Έ + 크기int[] arr = new int[10]; β€” λͺ¨λ“  μš”μ†Œ 0으둜 μ΄ˆκΈ°ν™”
λ¦¬ν„°λŸ΄ μ΄ˆκΈ°ν™”int[] arr = {1, 2, 3, 4, 5};
μ ‘κ·Όarr[i] β€” iλŠ” 0λΆ€ν„° arr.length - 1κΉŒμ§€
길이arr.length (속성, κ΄„ν˜Έ μ—†μŒ)
int[] arr = new int[5];
for (int i = 0; i < arr.length; i++) {
    arr[i] = i * i;  // 0, 1, 4, 9, 16
}
  • arr.length (속성) β€” κ΄„ν˜Έ X
  • 인덱슀 λ²”μœ„ 0 ~ arr.length - 1
  • String 배열은 String[] s = new String[n]; β†’ λͺ¨λ‘ null
CED 원문: "Arrays in Java can store either primitive data or object reference data." "When an array is created using the keyword new, all elements are initialized with a specific initial value..." (CED Topic 6.1)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: arr.length() ← λ©”μ„œλ“œ X, 속성. i <= arr.length β†’ AIOOBE. String[] new둜 λ§Œλ“€λ©΄ null이라 .equals() 호좜 μ‹œ NPE.
8
ArrayList λ©”μ„œλ“œ (add / get / set / remove / size)
🎨 μž‘μ„± Unit 4 U4.8U4.9
importimport java.util.ArrayList; (FRQ에선 μžλ™ κ°€μ •)
생성ArrayList<Integer> list = new ArrayList<>(); (μ œλ„€λ¦­μ€ wrapper class ν•„μˆ˜)
핡심 λ©”μ„œλ“œ.add(x), .add(i, x), .get(i), .set(i, x), .remove(i), .size()
크기.size() β€” λ©”μ„œλ“œ, κ΄„ν˜Έ ν•„μˆ˜
ArrayList<Integer> nums = new ArrayList<>();
nums.add(10);
nums.add(20);
nums.set(0, 99);  // nums = [99, 20]
nums.remove(0);     // nums = [20]; indices shift
int n = nums.size();
  • μ œλ„€λ¦­μ€ wrapper (Integer/Double/Boolean) β€” primitive λΆˆκ°€
  • .size() λ©”μ„œλ“œ (κ΄„ν˜Έ ν•„μˆ˜) vs λ°°μ—΄ .length
  • .remove(i) ν›„ μΈλ±μŠ€κ°€ μ•žμœΌλ‘œ μ‹œν”„νŠΈ
CED 원문: "An ArrayList object is mutable and contains object references." "ArrayList<E> β€” E specifies the type of the elements." (CED Topic 7.1)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: list.length (X) ← λ°°μ—΄ 속성. ArrayList<int> (X) ← primitive μ•ˆ 됨, Integer둜. λ£¨ν”„μ—μ„œ .remove() ν›„ 인덱슀 κ·ΈλŒ€λ‘œ 두면 element κ±΄λ„ˆλœ€.
9
2D λ°°μ—΄ β€” ν–‰/μ—΄ 처리 (Matrix)
🎨 μž‘μ„± Unit 4 U4.11U4.12
μ„ μ–Έint[][] grid = new int[r][c];
λ¦¬ν„°λŸ΄int[][] g = {{1,2},{3,4}};
ν–‰/μ—΄ 수grid.length = ν–‰, grid[0].length = μ—΄
μ ‘κ·Όgrid[row][col] β€” row λ¨Όμ €, col λ‹€μŒ
// row-major traversal β€” sum all elements
int[][] grid = new int[3][4];
int sum = 0;
for (int r = 0; r < grid.length; r++) {
    for (int c = 0; c < grid[0].length; c++) {
        sum += grid[r][c];
    }
}
  • grid.length = ν–‰ 수 / grid[0].length = μ—΄ 수
  • row-major 순회: λ°”κΉ₯ = ν–‰, μ•ˆμͺ½ = μ—΄
  • 2D for-each: for (int[] row : grid) for (int x : row)
CED 원문: "Two-dimensional arrays are stored as arrays of arrays." "Nested iteration statements are used to traverse and access all elements in a 2D array." (CED Topic 8.1, 8.2)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: ν–‰κ³Ό μ—΄ 인덱슀 ν˜Όλ™ β€” grid[c][r] ← (X). 순회 μ‹œ grid.length(ν–‰)와 grid[0].length(μ—΄) μœ„μΉ˜ 거꾸둜.
10
μž¬κ·€ (Base Case + Recursive Case) ⭐ 빈좜
🎨 μž‘μ„± Unit 10 U4.16U4.17
ꡬ쑰① Base case (μ’…λ£Œ 쑰건) β‘‘ Recursive case (자기 호좜, base case둜 수렴)
μ „ν˜•factorial, sum, gcd, binary search, mergesort
주의base caseκ°€ λ¨Όμ € 와야 β€” κ·Έλž˜μ•Ό λ¬΄ν•œ 호좜 차단
public static int factorial(int n) {
    if (n <= 1) return 1;          // base case
    return n * factorial(n - 1); // recursive case β†’ converges to n=1
}
  • Base case λͺ…μ‹œ (n <= 1 λ“±)
  • μž¬κ·€ 호좜이 base case둜 수렴 (n - 1, n / 2 λ“±)
  • return κ°’ μ •ν™• (factorial은 1, sum은 0)
CED 원문: "A recursive method is a method that calls itself." "Recursive methods contain at least one base case and at least one recursive call." (CED Topic 10.1)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: Base case λˆ„λ½ β†’ StackOverflowError. factorial(n + 1) ← λ°œμ‚° (수렴 μ•ˆ 함). 음수 μž…λ ₯ 처리 λ―ΈλΉ„ μ‹œ λ¬΄ν•œ μž¬κ·€.
11
상속 (extends) + super 호좜
🎨 μž‘μ„± Unit 9 extendssuper
extendspublic class Sub extends Base { ... }
super μƒμ„±μžμ„œλΈŒν΄λž˜μŠ€ μƒμ„±μž 첫 쀄: super(args);
super λ©”μ„œλ“œsuper.methodName(args) β€” λΆ€λͺ¨ λ©”μ„œλ“œ 호좜
override같은 μ‹œκ·Έλ‹ˆμ²˜λ‘œ μž¬μ •μ˜ (@Override annotation ꢌμž₯)
public class Vehicle {
    private int wheels;
    public Vehicle(int wheels) { this.wheels = wheels; }
}

public class Car extends Vehicle {
    private String model;
    public Car(String model) {
        super(4);  // must be FIRST line
        this.model = model;
    }
}
  • super(...)λŠ” μƒμ„±μž 첫 μ€„μ—λ§Œ κ°€λŠ₯
  • λΆ€λͺ¨μ— no-arg constructor μ—†μœΌλ©΄ μžμ‹μ—μ„œ super(...) λͺ…μ‹œ ν•„μˆ˜
  • private ν•„λ“œλŠ” 직접 μ ‘κ·Ό λΆˆκ°€ β†’ getter μ‚¬μš©
CED 원문: "A subclass inherits accessible methods and instance variables from its superclass." "The keyword super is used to refer to the immediate superclass." (CED Topic 9.2, 9.4)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: super(...)λ₯Ό μƒμ„±μž 두 번째 쀄 이후에 호좜 β†’ 컴파일 μ—λŸ¬. super.toString() 같은 ν˜ΈμΆœμ€ μœ„μΉ˜ 자유.
12
μΈν„°νŽ˜μ΄μŠ€ κ΅¬ν˜„ (implements + Comparable)
🎨 μž‘μ„± Unit 9 interfaceComparable
ꡬ쑰public class X implements MyInterface { ... }
의무interface의 λͺ¨λ“  λ©”μ„œλ“œ κ΅¬ν˜„ (abstract λ©”μ„œλ“œ)
Comparablepublic int compareTo(T other) β†’ 음수/0/μ–‘μˆ˜ λ°˜ν™˜
public class Score implements Comparable<Score> {
    private int value;

    public Score(int value) { this.value = value; }

    public int compareTo(Score other) {
        return this.value - other.value;  // neg / 0 / pos
    }
}
  • interface의 λͺ¨λ“  λ©”μ„œλ“œ κ΅¬ν˜„ (μ•ˆ ν•˜λ©΄ 컴파일 X)
  • compareTo λ°˜ν™˜μ€ 음수(less) / 0(equal) / μ–‘μˆ˜(greater)
  • μ œλ„€λ¦­ Comparable<Score> λͺ…μ‹œ
CED 원문: "Interface β€” A reference type that contains a list of abstract methods that any non-abstract class implementing the interface must override." (CED p.13)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: compareToμ—μ„œ true/false return ← (X) int λ°˜ν™˜. this.value > other.value ← (X) 그건 boolean이라 컴파일 μ•ˆλ¨.
13
λ‹€ν˜•μ„± (Polymorphism) + instanceof + downcast
🎨 μž‘μ„± Unit 9 polymorphism
upcastμžλ™: Animal a = new Dog();
downcastλͺ…μ‹œ: Dog d = (Dog) a; β€” 캐슀트 μ‹€νŒ¨ μ‹œ ClassCastException
μ•ˆμ „ 체크if (a instanceof Dog) { Dog d = (Dog) a; ... }
Object obj = "hello";
if (obj instanceof String) {
    String s = (String) obj;     // safe downcast
    System.out.println(s.length());
}
  • downcast μ „ instanceof둜 μ•ˆμ „ 체크
  • 호좜 λ©”μ„œλ“œλŠ” μ‹€μ œ 객체 νƒ€μž…μ˜ override 버전 (dynamic dispatch)
  • μ ‘κ·Ό κ°€λŠ₯ν•œ λ©€λ²„λŠ” μ°Έμ‘° νƒ€μž…μ— 따름 (정적)
CED 원문: "Polymorphism β€” When a method is called, the actual method executed is determined at run-time based on the type of the object." (CED p.13, Topic 9.6)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: instanceof 체크 없이 κ°•μ œ cast β†’ ClassCastException. Animal a = new Cat(); Dog d = (Dog) a; λŸ°νƒ€μž„μ— 폭발.
14
String λ©”μ„œλ“œ (length / substring / indexOf / equals / charAt)
🎨 μž‘μ„± Unit 1Β·2 U1.15
.length()문자 개수 β€” λ©”μ„œλ“œ, κ΄„ν˜Έ ν•„μˆ˜
.substring(i, j)인덱슀 [i, j) β€” jλŠ” 미포함
.substring(i)iλΆ€ν„° λκΉŒμ§€
.indexOf("x")처음 발견 μœ„μΉ˜, μ—†μœΌλ©΄ -1
.equals(t)λ‚΄μš© 비ꡐ (λŒ€μ†Œλ¬Έμž ꡬ뢄)
.charAt(i)i번째 문자 β†’ λ°˜ν™˜ νƒ€μž… char
String s = "hello";
int n   = s.length();        // 5
String t = s.substring(1, 4);  // "ell"
int p   = s.indexOf("l");     // 2
char c  = s.charAt(0);       // 'h'
boolean b = s.equals("hello"); // true
  • substring(i, j)λŠ” [i, j) 반-κ°œκ΅¬κ°„ (j 미포함)
  • charAt λ°˜ν™˜μ€ char (String μ•„λ‹˜!)
  • String λΉ„κ΅λŠ” 항상 .equals()
CED 원문: "Strings are objects whose values cannot change." "Indexing in Strings is zero-based." (CED Topic 2.9, Java Quick Reference)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: s.substring(0, s.length()) = 전체. s.substring(0, s.length() - 1)λŠ” λ§ˆμ§€λ§‰ 문자 μ œμ™Έ. charAt κ²°κ³Όλ₯Ό String으둜 μ“°λ©΄ 컴파일 μ—λŸ¬.
15
Math 클래슀 (abs / pow / sqrt / random)
🎨 μž‘μ„± Unit 1 U1.11
Math.abs(x)μ ˆλŒ“κ°’ β€” int λ˜λŠ” double λ°˜ν™˜ (μž…λ ₯ νƒ€μž… 따라)
Math.pow(b, e)b^e β€” double λ°˜ν™˜ (int ν•„μš”μ‹œ cast)
Math.sqrt(x)제곱근 β€” double λ°˜ν™˜
Math.random()0.0 ≀ r < 1.0 β€” 1.0은 미포함
int a = Math.abs(-5);              // 5
double p = Math.pow(2, 10);         // 1024.0
int q = (int) Math.pow(2, 10);   // 1024 β€” cast required
double r = Math.sqrt(16);            // 4.0

// random integer in [low, high]
int rand = (int)(Math.random() * (high - low + 1)) + low;
  • Math.pow λ°˜ν™˜ = double (int에 λŒ€μž…ν•˜λ €λ©΄ cast)
  • Math.random()은 < 1.0 (1.0 미포함)
  • μ •μˆ˜ λ²”μœ„ [low, high] 랜덀 곡식 μ•”κΈ°
CED 원문: "static int abs(int x), static double pow(double base, double exponent), static double random()" (Java Quick Reference)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: int x = Math.pow(2, 3); 컴파일 μ—λŸ¬ (double β†’ int μžλ™ X). Math.random() * 10λŠ” 0~9.99... β†’ castν•˜λ©΄ 0~9 (10 미포함).
16
μ˜ˆμ™Έ (NPE / AIOOBE / ClassCast / Arithmetic)
🎨 μž‘μ„± μ „λ°˜ RuntimeException
NullPointerException (NPE)null.method() λ˜λŠ” null.field μ ‘κ·Ό
ArrayIndexOutOfBoundsException인덱슀 < 0 λ˜λŠ” β‰₯ arr.length
IndexOutOfBoundsExceptionArrayList의 잘λͺ»λœ 인덱슀 (list.get(size()) λ“±)
ClassCastException잘λͺ»λœ downcast (μ‹€μ œ νƒ€μž…κ³Ό cast νƒ€μž… 뢈일치)
ArithmeticExceptionμ •μˆ˜ 0 λ‚˜λˆ„κΈ° (double / 0.0 = Infinity, μ˜ˆμ™Έ X)
// NPE example β€” uninitialized String[]
String[] words = new String[3];
words[0].length();  // NullPointerException β€” words[0] is null

// AIOOBE example
int[] arr = {1, 2, 3};
int x = arr[3];   // ArrayIndexOutOfBoundsException

// ArithmeticException β€” int only
int y = 5 / 0;     // ArithmeticException
  • 각 μ˜ˆμ™Έμ˜ λ°œμƒ 쑰건 ν•œ 쀄 μ•”κΈ° (MCQ 빈좜)
  • FRQμ—μ„œ try/catchλŠ” 좜제 μ•ˆ 됨 β€” λ°œμƒ 쑰건만 μ•Œλ©΄ 됨
  • NPE λ°©μ§€: 객체 μ‚¬μš© μ „ null 체크
CED 원문: "An ArrayIndexOutOfBoundsException is thrown when an attempt is made to access an array element using an index that is outside the bounds of the array." (CED Topic 6.1)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: 5.0 / 0 = Infinity (μ˜ˆμ™Έ X). 5 / 0 = ArithmeticException. for-each μ•ˆμ—μ„œ list.remove β†’ ConcurrentModificationException.
17
Object 비ꡐ: == vs .equals() ⭐ MCQ 1μˆœμœ„
🎨 μž‘μ„± Unit 1Β·3Β·5 U1.15U3.5
primitive (int, double, boolean, char)== μ‚¬μš© β€” κ°’ 비ꡐ
객체 (String, Integer, μ‚¬μš©μž 클래슀).equals() μ‚¬μš© β€” λ‚΄μš© 비ꡐ
== on 객체참쑰(μ£Όμ†Œ) 비ꡐ β€” 같은 λ©”λͺ¨λ¦¬λ©΄ true
null 비ꡐobj == null은 μ•ˆμ „ (NPE μ•ˆ 남)
String a = new String("hi");
String b = new String("hi");

boolean x = (a == b);         // false β€” different memory
boolean y = a.equals(b);     // true  β€” same content

// primitive β€” == is correct
int p = 5, q = 5;
boolean z = (p == q);         // true
  • primitive: == / 객체: .equals()
  • String literal끼리 ==λŠ” μ’…μ’… true (string pool) β€” μš΄μ— μ˜μ‘΄ν•˜μ§€ 말 것
  • μ‚¬μš©μž μ •μ˜ ν΄λž˜μŠ€μ—μ„œ .equals() override μ•ˆ ν•˜λ©΄ Object의 == λ™μž‘
CED 원문: "When the operator == is used to compare object references, it returns true if both reference variables refer to the same object." "The String class equals method returns true if the strings are identical." (CED Topic 2.9, 5.7)
πŸ“Œ 자주 ν‹€λ¦¬λŠ”: if (s == "hello") ← 가끔 true, 가끔 false (디버깅 μ§€μ˜₯). 항상 .equals() μ‚¬μš©. Integer도 Integer i = 200; Integer j = 200; i == j;λŠ” false (cache λ²”μœ„ -128~127 λ°–).

πŸ“– 읽기·뢄석 β€” Practice 3 "Analyze Code" (MCQ 37–53% 비쀑)

MCQμ—μ„œλŠ” μ½”λ“œλ₯Ό 읽고 좜λ ₯ / λ³€μˆ˜ μ΅œμ’…κ°’ / 호좜 횟수λ₯Ό μ˜ˆμΈ‘ν•˜λŠ” trace λ¬Έμ œκ°€ κ°€μž₯ λ§Žλ‹€. 같은 17 νŒ¨ν„΄μ„ trace μ‹œλ‚˜λ¦¬μ˜€λ‘œ μ••μΆ•.

1
Class / Constructor β€” 객체 μƒνƒœ 좔적
πŸ“– 뢄석Unit 3
Student s1 = new Student("Min", 11);
Student s2 = s1;
s2.setGrade(12);
System.out.println(s1.getGrade());  // ?

좜λ ₯: 12 β€” s1κ³Ό s2κ°€ 같은 객체λ₯Ό μ°Έμ‘° (aliasing).

πŸ“Œ trace 핡심: 객체 λŒ€μž…μ€ μ°Έμ‘° 볡사. ν•œμͺ½μ—μ„œ λ³€κ²½ν•˜λ©΄ λ‹€λ₯Έ μͺ½λ„ 변함.
2
Method Header β€” 호좜 λ§€μΉ­
πŸ“– 뢄석Unit 1Β·3
public static int f(int x)        { return x; }
public static int f(int x, int y) { return x + y; }
System.out.println(f(3, 4));  // ?

좜λ ₯: 7 β€” overloadλŠ” λ§€κ°œλ³€μˆ˜ 개수/νƒ€μž…μœΌλ‘œ ꡬ뢄.

πŸ“Œ trace 핡심: overloadλŠ” return type λ‹€λ₯Έ 걸둜 ꡬ뢄 μ•ˆ 됨. λ§€κ°œλ³€μˆ˜ μ‹œκ·Έλ‹ˆμ²˜λ§Œ.
3
for 루프 β€” 반볡 횟수
πŸ“– 뢄석Unit 2
int count = 0;
for (int i = 5; i < 15; i += 2) count++;
System.out.println(count);  // ?

좜λ ₯: 5 β€” i = 5, 7, 9, 11, 13 β†’ 5회.

πŸ“Œ trace 핡심: μ’…λ£Œμ‘°κ±΄ < 15μ΄λ―€λ‘œ 13κΉŒμ§€. (stop - start + step - 1) / step 곡식 검증.
4
while β€” μ’…λ£Œ 쑰건 좔적
πŸ“– 뢄석Unit 2
int n = 100, k = 0;
while (n > 0) { n /= 3; k++; }
System.out.println(k);  // ?

좜λ ₯: 5 β€” 100 β†’ 33 β†’ 11 β†’ 3 β†’ 1 β†’ 0 (5회).

πŸ“Œ trace 핡심: int λ‚˜λˆ—μ…ˆμ€ floor. 1 / 3 = 0 (μ†Œμˆ˜μ  버림).
5
for-each β€” 원본 λ―Έλ³€κ²½
πŸ“– 뢄석Unit 4
int[] arr = {1, 2, 3};
for (int x : arr) x = x * 10;
System.out.println(arr[0]);  // ?

좜λ ₯: 1 β€” for-each λ³€μˆ˜λŠ” 볡사본. 원본 λ°°μ—΄ λ³€κ²½ μ•ˆ 됨.

πŸ“Œ trace 핡심: 객체 λ°°μ—΄μ—μ„œλŠ” for-each둜 객체 λ©”μ„œλ“œ 호좜 μ‹œ μƒνƒœ 변경은 κ°€λŠ₯ (μ°Έμ‘° 볡사). primitiveλŠ” μ ˆλŒ€ X.
6
if-else β€” 단좕평가 (short-circuit)
πŸ“– 뢄석Unit 2
String s = null;
if (s != null && s.length() > 0) {
    System.out.println("non-empty");
} else {
    System.out.println("null or empty");
}

좜λ ₯: null or empty β€” &&의 λ‹¨μΆ•ν‰κ°€λ‘œ s.length()κ°€ ν˜ΈμΆœλ˜μ§€ μ•Šμ•„ NPE λ°©μ§€.

πŸ“Œ trace 핡심: && μ™Όμͺ½μ΄ falseλ©΄ 였λ₯Έμͺ½ 평가 μ•ˆ 함. ||λŠ” μ™Όμͺ½ trueλ©΄ 였λ₯Έμͺ½ 평가 μ•ˆ 함.
7
Array β€” 인덱슀 경계
πŸ“– 뢄석Unit 4
int[] a = new int[5];
for (int i = 0; i <= a.length; i++) a[i] = i;

κ²°κ³Ό: ArrayIndexOutOfBoundsException β€” i = 5μ—μ„œ a[5] μ ‘κ·Ό (유효 인덱슀 0~4).

πŸ“Œ trace 핡심: i <= length = 거의 항상 AIOOBE. i < lengthκ°€ μ •λ‹΅.
8
ArrayList β€” remove 인덱슀 μ‹œν”„νŠΈ
πŸ“– 뢄석Unit 4
ArrayList<Integer> list = new ArrayList<>();
list.add(1); list.add(2); list.add(3); list.add(4);
for (int i = 0; i < list.size(); i++) {
    if (list.get(i) % 2 == 0) list.remove(i);
}
System.out.println(list);  // ?

좜λ ₯: [1, 3]… 처럼 λ³΄μ΄μ§€λ§Œ μ‹€μ œ: [1, 3]. 잠깐, trace해보면: i=0 β†’ 1 (ν™€μˆ˜) keep, i=1 β†’ 2 (짝수) remove β†’ list=[1,3,4], i=2 β†’ 4 (짝수) remove β†’ [1,3]. κ²°κ³Ό [1, 3]. λ‹€λ§Œ μ§μˆ˜κ°€ 연속이면 κ±΄λ„ˆλœ€ μœ„ν—˜.

πŸ“Œ trace 핡심: remove(i) ν›„ i++ ν•˜λ©΄ λ‹€μŒ element κ±΄λ„ˆλœ€. 짝수 연속 λ°μ΄ν„°μ—μ„œ 빈좜 함정.
9
2D Array β€” row/col ν˜Όλ™ trap
πŸ“– 뢄석Unit 4
int[][] g = {{1,2,3},{4,5,6}};
System.out.println(g.length + " " + g[0].length);

좜λ ₯: 2 3 β€” g.length = ν–‰ 수(2), g[0].length = μ—΄ 수(3).

πŸ“Œ trace 핡심: λ°”κΉ₯ = ν–‰, μ•ˆμͺ½ = μ—΄. λ°˜λŒ€λ‘œ μ™Έμš°λ©΄ λͺ¨λ“  2D 문제 λ‹€ ν‹€λ¦Ό.
10
μž¬κ·€ β€” 호좜 μŠ€νƒ trace
πŸ“– 뢄석Unit 10
public static int m(int n) {
    if (n <= 1) return 1;
    return 2 * m(n - 1);
}
System.out.println(m(5));  // ?

좜λ ₯: 16 β€” m(5)=2Β·m(4), m(4)=2Β·m(3), …, m(1)=1 β†’ 2⁴ = 16.

πŸ“Œ trace 핡심: μž¬κ·€λŠ” μ•ˆμ—μ„œλΆ€ν„° ν’€μ–΄ 올라옴. base case 도달 ν›„ κ³±μ…ˆ λˆ„μ .
11
상속 β€” override 호좜 (dynamic dispatch)
πŸ“– 뢄석Unit 9
Animal a = new Dog();   // upcast
a.speak();              // "Woof" β€” Dog's override runs

좜λ ₯: Woof β€” μ°Έμ‘° νƒ€μž…μ€ Animalμ΄μ§€λ§Œ μ‹€μ œ 객체가 Dogμ΄λ―€λ‘œ Dog의 speak() μ‹€ν–‰.

πŸ“Œ trace 핡심: λ©”μ„œλ“œ ν˜ΈμΆœμ€ μ‹€μ œ 객체 νƒ€μž…μœΌλ‘œ κ²°μ • (λŸ°νƒ€μž„). ν•„λ“œ 접근은 μ°Έμ‘° νƒ€μž… (정적). λ©”μ„œλ“œ vs ν•„λ“œ 차이 핡심.
12
Interface β€” compareTo κ²°κ³Ό 해석
πŸ“– 뢄석Unit 9
String s = "apple", t = "banana";
int r = s.compareTo(t);  // ?

κ²°κ³Ό: r < 0 (음수) β€” "apple"이 "banana"보닀 μ‚¬μ „μˆœ μ•ž. μ •ν™•ν•œ 값은 ('a'-'b') = -1.

πŸ“Œ trace 핡심: compareToλŠ” 음수/0/μ–‘μˆ˜ λΆ€ν˜Έλ§Œ 따짐. μ •ν™•ν•œ κ°’ μ™ΈμšΈ ν•„μš” μ—†μŒ.
13
Polymorphism β€” instanceof + cast
πŸ“– 뢄석Unit 9
Object[] objs = {"hi", 42, 3.14};
int count = 0;
for (Object o : objs) {
    if (o instanceof String) count++;
}
System.out.println(count);

좜λ ₯: 1 β€” String은 "hi" 1개. 42λŠ” Integer (autoboxing), 3.14λŠ” Double.

πŸ“Œ trace 핡심: autoboxing으둜 primitive λ¦¬ν„°λŸ΄μ΄ wrapper 객체가 됨. instanceof IntegerλŠ” true, instanceof String은 false.
14
String β€” substring 경계
πŸ“– 뢄석Unit 1Β·2
String s = "abcdef";
System.out.println(s.substring(2, 5));  // ?
System.out.println(s.substring(3));     // ?

좜λ ₯: cde / def β€” substring(2,5)λŠ” 인덱슀 2,3,4 (5 미포함). substring(3)은 λκΉŒμ§€.

πŸ“Œ trace 핡심: [start, end) 반-κ°œκ΅¬κ°„. endλŠ” 포함 μ•ˆ 됨. κΈΈμ΄λŠ” end - start.
15
Math β€” int μΊμŠ€νŒ… trap
πŸ“– 뢄석Unit 1
int x = (int)(Math.random() * 10);  // range?

x의 λ²”μœ„: 0 ≀ x ≀ 9 (μ •μˆ˜). Math.random() ∈ [0.0, 1.0) β†’ Γ—10 = [0.0, 10.0) β†’ cast = 0~9.

πŸ“Œ trace 핡심: (int) castλŠ” floor (μ†Œμˆ˜μ  버림). -3.7 β†’ -3 (μŒμˆ˜λ„ 0 μͺ½μœΌλ‘œ μ ˆλ‹¨).
16
μ˜ˆμ™Έ β€” μ–΄λ–€ μ˜ˆμ™Έκ°€ λ°œμƒν•˜λŠ”κ°€
πŸ“– λΆ„μ„μ „λ°˜
String s = null;
System.out.println(s.length());  // μ–΄λ–€ μ˜ˆμ™Έ?

μ˜ˆμ™Έ: NullPointerException β€” null 객체에 λ©”μ„œλ“œ 호좜.

πŸ“Œ trace 핡심: μ˜ˆμ™Έ μ’…λ₯˜μ™€ λ°œμƒ 쑰건 맀칭은 MCQ 빈좜. NPE / AIOOBE / ClassCast / Arithmetic 4μ’….
17
== vs .equals() β€” κ²°κ³Ό 차이
πŸ“– 뢄석Unit 1Β·5
String a = new String("AP");
String b = new String("AP");
System.out.println(a == b);
System.out.println(a.equals(b));

좜λ ₯: false / true β€” new String은 별도 λ©”λͺ¨λ¦¬. == μ°Έμ‘° 비ꡐ false. .equals λ‚΄μš© 비ꡐ true.

πŸ“Œ trace 핡심: new ν‚€μ›Œλ“œ 보면 == false 거의 ν™•μ •. literal끼리 ("AP" == "AP")λŠ” true κ°€λŠ₯ (string pool).

πŸ“‹ μ’…ν•© 정리

17
직접 μž‘μ„± νŒ¨ν„΄
17
읽기·뢄석 νŒ¨ν„΄
10
CED Unit 컀버

🎯 μ‹œν—˜ 직전 1μ£Ό β€” Code Pattern λ§ˆμŠ€ν„° 체크리슀트 (localStorage μžλ™ μ €μž₯)

각 νŒ¨ν„΄ 3단계: βœ… 외움 / πŸ‘ 트레이슀 κ°€λŠ₯ / πŸš€ 0μ΄ˆμ— μž‘μ„±. μ²΄ν¬λ°•μŠ€ λˆ„λ₯΄λ©΄ μžλ™ μ €μž₯λœλ‹€.

진도: λ‘œλ”© 쀑…
#νŒ¨ν„΄βœ… μ™Έμ›€πŸ‘ νŠΈλ ˆμ΄μŠ€πŸš€ 0초 μž‘μ„±
1Class + Constructor
2Method Header
3for 루프
4while 루프
5for-each
6if-else
7Array (1D)
8ArrayList
92D Array
10μž¬κ·€
11상속 + super
12Interface (Comparable)
13Polymorphism
14String λ©”μ„œλ“œ
15Math λ©”μ„œλ“œ
16μ˜ˆμ™Έ
17== vs .equals()

πŸ—“ D-Day ν•™μŠ΅ κ³„νš

λ‚ μ§œν•΄μ•Ό ν•  것
D-5 (였늘)이 νŽ˜μ΄μ§€ 1회 정독. 17개 νŒ¨ν„΄ 머리에 μŒ“κΈ°. 직접 μž‘μ„± νƒ­λ§Œ 보고 빈 쒅이에 1Β·2Β·6Β·7Β·8Β·10번 5개 μ½”λ”©.
D-4읽기·뢄석 νƒ­ 17개 trace 풀이. λ‹΅ 가리고 좜λ ₯ 예츑 β†’ μ •λ‹΅ 확인.
D-3FRQ Q1~Q4 1μ„ΈνŠΈ 풀이. 각 λ¬Έμ œλ§ˆλ‹€ μ–΄λ–€ νŒ¨ν„΄ 쑰합인지 λ§ˆν‚Ή.
D-2== vs .equals(), substring 경계, AIOOBE, NPE β€” MCQ 빈좜 4μ’… 집쀑. ν•œκ΅­ 학생 빈좜 μ‹€μˆ˜ Top 5 λ‹€μ‹œ 점검.
D-1νŒ¨ν„΄ 11~13 (상속/μΈν„°νŽ˜μ΄μŠ€/λ‹€ν˜•μ„±)만 별도 정리. polymorphism trace 5문제 더.
D-0 (μ‹œν—˜μΌ)이 νŽ˜μ΄μ§€ 30λΆ„ 정독 + Java Quick Reference ν•œ μž₯ 좜λ ₯ν•΄ μ™ΈμΆœ 직전 ν›‘κΈ°.

⚠️ ν•œκ΅­ 학생 빈좜 μ‹€μˆ˜ Top 5

μ‹€μˆ˜μ˜ν–₯
return λˆ„λ½ β€” return type μžˆλŠ” λ©”μ„œλ“œμ—μ„œ 일뢀 뢄기에 return μ•ˆ 씀FRQ βˆ’1점 (compile error)
public ν‚€μ›Œλ“œ λˆ„λ½ β€” class / method header에 빠뜨림FRQ βˆ’1점 (header 채점)
μ„Έλ―Έμ½œλ‘  ; λˆ„λ½ β€” ν•œκ΅­μ‹ μž‘μ„± μŠ΅κ΄€μ—μ„œ 자주 빠짐FRQ βˆ’1~2점 (λͺ¨λ“  λ¬Έμž₯ 끝)
== vs .equals() ν˜Όλ™ β€” String/Integer 비ꡐ에 == μ‚¬μš©MCQ 1μˆœμœ„ 함정 / FRQ 의미 손싀
ArrayList .size() vs λ°°μ—΄ .length ν˜Όλ™ β€” κ΄„ν˜Έ λΉ λœ¨λ¦¬κ±°λ‚˜ λ”λΆ™μž„FRQ compile error / MCQ ν—·κ°ˆλ¦Ό

πŸ“Œ νŒ¨ν„΄λ³„ 빈좜 task verb λ§€ν•‘

Task VerbλŒ€ν‘œ νŒ¨ν„΄μš”κ΅¬
Write the method2, 3, 5, 7, 8, 10, 14method header + body + return λͺ¨λ‘ μ •ν™•
Write the class1, 2, 11, 12class header + ν•„λ“œ + μƒμ„±μž + λ©”μ„œλ“œ λͺ¨λ‘
What is the output전체 17 (특히 3, 4, 5, 8, 10)λ³€μˆ˜ μƒνƒœ 좔적 β†’ μ΅œμ’… 좜λ ₯
What is the value3, 4, 6, 14, 15νŠΉμ • λ³€μˆ˜μ˜ trace ν›„ κ°’
Which exception16NPE / AIOOBE / ClassCast / Arithmetic λ§€μΉ­

πŸ”— 같이 보면 쒋은 자료

AP CSA Code Patterns Checklist Β· 2026-05-02 Β· CED V.1 Β· μ •μ—°μ΄μš©
좜처: College Board CED V.1 (2020) Β· Course Framework Unit 1–10 Β· Java Quick Reference (Appendix) Β· Practice 2 Develop + Practice 3 Analyze