Skip to content · ⁨דלג לתוכן⁩
Subjects · ⁨נושאים⁩

AP Computer Science A · ⁨מדעי מחשב A - AP⁩

Tips · ⁨טיפים⁩

AP Computer Science A הוא קורס Java: אובייקטים וכיתות, טיפים פרמיטיביים וזרימת בקרה, כתיבת כיתות, מערכות ו-Al ArrayLists, מערכות ⟨2D, ירישה ופולימוRFיזם, ורקורסיה. זהו קורס תכנות ראשון המלמד עם קוד אובייקטי אמיתי, ולא פסאו-קוד.

כל ארבע השאלות הפתוחות הן Java בכתיב יד. אין מחשב שיקלף עבורכם נקודה חסרה או סוג החזרה שגוי, לכן כתבו קוד על נייר בזמן ההכנה — זו מיומנות שונה מהכתיבה במחשב.

מערכות ו-Al ArrayLists הן הנושא הנבדק ביותר. שיפוע עם סיור, הכנסה והסרה, וידע באיזה אינדקס מתזז כשמוסים אלמנט, משתלם יותר מכל שעת אימון אחת.

העמודים מכסים את יחידות CED ב-Java, עם דוגמאות תוכנה שניתן לערוך בדפדפן. במאגר זמינים FRQs ישנים ומדריכי ניקוד — כולן שאלות כתיבת קוד, לכן הפתרונות המוצגים הם מתודות שלמות ולא מקטעים.

  • 1

    Using Objects and Methods · ⁨שימוש באובייקטים ובשיטות⁩

    Watch lesson · ⁨צפה בשיעור⁩
    1.1

    Introduction to Algorithms, Programming, and Compilers

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.1.A: Represent patterns and algorithms found in everyday life using written language or diagrams.

    • 1.1.A.1 Algorithms define step-by-step processes to follow when completing a task or solving a problem. These algorithms can be represented using written language or diagrams.
    • 1.1.A.2 Sequencing defines an order for when steps in a process are completed. Steps in a process are completed one at a time.

    Learning Objective 1.1.B: Explain the code compilation and execution process.

    • 1.1.B.1 Code can be written in any text editor; however, an integrated development environment (IDE) is often used to write programs because it provides tools for a programmer to write, compile, and run code.
    • 1.1.B.2 A compiler checks code for some errors. Errors detectable by the compiler need to be fixed before the program can be run.

    Learning Objective 1.1.C: Identify types of programming errors.

    • 1.1.C.1 A syntax error is a mistake in the program where the rules of the programming language are not followed. These errors are detected by the compiler.
    • 1.1.C.2 A logic error is a mistake in the algorithm or program that causes it to behave incorrectly or unexpectedly. These errors are detected by testing the program with specific data to see if it produces the expected outcome.
    • 1.1.C.3 A run-time error is a mistake in the program that occurs during the execution of a program. Run-time errors typically cause the program to terminate abnormally.
    • 1.1.C.4 An exception is a type of run-time error that occurs as a result of an unexpected error that was not detected by the compiler. It interrupts the normal flow of the program's execution.
    עברית

    מטרת הלמידה 1.1.A: ייצוג דפוסים ואלגוריתמים הנמצאים בחיי היומיום באמצעות כתיבה או דיאגרמות.

    • 1.1.A.1 אלגוריתמים מגדירים תהליכים צעד-צעד שיש לבצע בעת ביצוע משימה או פתרון בעיה. אלגוריתמים אלו יכולים להיות מיוצגים באמצעות כתיבה או דיאגרמות.
    • 1.1.A.2 רצף מגדיר סדר עבור ביצוע הצעדים בתהליך. צעדים בתהליך מתבצעים אחד אחרי השני.

    מטרת הלמידה 1.1.B: הסבר על תהליך ההרכבה והביצוע של קוד.

    • 1.1.B.1 קוד ניתן לכתיבה בכל עורך טקסט; עם זאת, משתמשים לעיתים קרובות ב-סביבת פיתוח משולבת (IDE) כדי לכתוב תוכניות, מכיוון שהיא מספקת כלים למפתח כדי לכתוב, להרכיב ולהפעיל קוד.
    • 1.1.B.2 מיישר בודק את הקוד לקיוום שגיאות מסוימות. שגיאות שניתן לגלות על ידי המיישר חייבות לתוקן לפני שהתוכנית תוכל להפעיל.

    מטרת הלמידה 1.1.C: זיהוי סוגי שגיאות בתכנות.

    • 1.1.C.1 שגיאת סינטקס היא טעות בתוכנית בה כללי לשפת התכנות אינם נעלמו. שגיאות אלו נזקפות על ידי המיישר.
    • 1.1.C.2 שגיאת לוגיקה היא טעות באלגוריתם או בתוכנית הגורמת להתנהגות לא נכונה או לא צפויה. שגיאות אלו נזקפות על ידי בדיקת התוכנית עם נתונים ספציפיים כדי לוודא שהיא מייצרת את התוצאה הרצויה.
    • 1.1.C.3 שגיאת ריצה היא טעות בתוכנית שקורה במהלך הביצוע של תוכנית. שגיאות ריצה גורמות לרוב להפסקת התוכנית בצורה לא תקינה.
    • 1.1.C.4 חריגה היא סוג של שגיאת ריצה הנובעת מאירוע בלתי צפוי שלא נזקף על ידי המיישר. היא מפסיקה את זרימת הביצוע הרגילה של התוכנית.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Source code on a workstation — programs are written, compiled, and run as precise instructions
    Source code on a workstation — programs are written, compiled, and run as precise instructions

    An algorithm 算法 is a finite, step-by-step procedure that solves a problem. A program 程序 expresses an algorithm in a language a computer can run. Java is compiled 编译: the compiler 编译器 translates your source code into bytecode, which the Java Virtual Machine (JVM) runs. A syntax error 语法错误 (breaking the grammar) is caught by the compiler; a logic error 逻辑错误 (wrong result) is not – the program runs but misbehaves.

    A compiler translates the whole program at once; an interpreter runs it line by line
    A compiler translates the whole program at once; an interpreter runs it line by line
    Several computer processor chips seen from below
    Your Java program is compiled to instructions a CPU like one of these actually runs
    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    algorithm/ˈælɡərɪθəm/ אלגוריתם
    program/ˈprəʊɡræm/ תוכנית מחשב
    compiled/kəmˈpaɪld/ עריכה
    compiler/kəmˈpaɪlə/ מתרגם
    syntax error/ˈsɪntæks ˈerə/ שגיאת סינטקס
    logic error/ˈlɒdʒɪk ˈerə/ שגיאת לוגיקה
    1.2

    Variables and Data Types

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.2.A: Identify the most appropriate data type category for a particular specification.

    • 1.2.A.1 A data type is a set of values and a corresponding set of operations on those values. Data types can be categorized as either primitive or reference.
    • 1.2.A.2 The primitive data types used in this course define the set of values and corresponding operations on those values for numbers and Boolean values.
    • 1.2.A.3 A reference type is used to define objects that are not primitive types.

    Learning Objective 1.2.B: Develop code to declare variables to store numbers and Boolean values.

    • 1.2.B.1 The three primitive data types used in this course are int, double, and boolean. An int value is an integer. A double value is a real number. A boolean value is either true or false.
      • Exclusion statement: The other five primitive data types (long, short, byte, float, and char) are outside the scope of the AP Computer Science A course and exam.
    • 1.2.B.2 A variable is a storage location that holds a value, which can change while the program is running. Every variable has a name and an associated data type. A variable of a primitive type holds a primitive value from that type.
    עברית

    יעד למידה 1.2.A: זיהוי סוג הנתונים המתאים ביותר לקטגוריה עבור ספקיפיקציה נתונה.

    • 1.2.A.1 סוג נתונים הוא קבוצת ערכים וקבוצת פעולות המתאימה לערכים אלו. סוגי נתונים יכולים להיות קטגוריזציה כ要么 primitive או reference.
    • 1.2.A.2 סוגי הנתונים ה-primitive המשמשים בקורס זה מגדירים את קבוצת הערכים ואת הפעולות המתאימות עליהם עבור מספרים וערכים בוליאניים.
    • 1.2.A.3 סוג ייחוס (reference type) משמש להגדרת אובייקטים שאינם סוגי primitive.

    יעד למידה 1.2.B: פיתוח קוד להצהרת משתנים לאחסון מספרים וערכים בוליאניים.

    • 1.2.B.1 שלושת סוגי הנתונים הפרימיטיביים המשתמשים בקורס הם int, double ו-boolean. ערך int הוא מספר שלם. ערך double הוא מספר אמיתי. ערך boolean הוא או true או false.
      • הודעת חריגה: חמישה סוגי נתונים primitive אחרים (long, short, byte, float ו-char) אינם בתחום הלימודים ובמבחן AP Computer Science A.
    • 1.2.B.2 משתנה הוא מקום אחסון המכיל ערך, שעלול להשתנות בעת ביצוע התוכנית. לכל משתנה יש שם וסוג נתונים הקשור אליו. משתנה מסוג primitive מכיל ערך primitive מאותו סוג.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    A variable 变量 is a named box that stores a value of a fixed type 类型. Java's main primitive types 基本类型 are int (whole numbers), double (decimals), and boolean (true/false). Declare with the type first:

    Java's basic data types, each storing a different kind of value
    Java's basic data types, each storing a different kind of value
    int score = 90;
    double price = 4.99;
    boolean passed = true;
    
    Explore · ⁨חקור⁩

    Explore how a variable holds one value at a time · ⁨חקור כיצד משתנה שומר ערך אחד בכל פעם⁩

    A variable is a named box that stores one value of a fixed type. Step through the lines and watch each box take its value; notice that reassigning score overwrites the old number rather than making a new box. · ⁨משתנה הוא תיבה בעלת שם שמאחסנת ערך אחד מסוג קבוע. צעדו לאורך השורות וצפו כל תיבה מקבלת את הערך שלה; שימו לב שהאתרה מחודשת score מחיקה המספר הישן במקום ליצור תיבה חדשה.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    variable/ˈveərɪəbl/ משתנה
    type/taɪp/ סוג
    primitive types/ˈprɪmɪtɪv taɪps/ סוגים primitive (בסיסיים)
    1.3

    Expressions and Output

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.3.A: Develop code to generate output and determine the result that would be displayed.

    • 1.3.A.1 System.out.print and System.out.println display information on the computer display. System.out.println moves the cursor to a new line after the information has been displayed, while System.out.print does not.

    Learning Objective 1.3.B: Develop code to utilize string literals and determine the result of using string literals.

    • 1.3.B.1 A literal is the code representation of a fixed value.
    • 1.3.B.2 A string literal is a sequence of characters enclosed in double quotes.
    • 1.3.B.3 Escape sequences are special sequences of characters that can be included in a string. They start with a \ and have a special meaning in Java. Escape sequences used in this course include double quote \", backslash \\, and newline \n.

    Learning Objective 1.3.C: Develop code for arithmetic expressions and determine the result of these expressions.

    • 1.3.C.1 Arithmetic expressions, which consist of numeric values, variables, and operators, include expressions of type int and double.
    • 1.3.C.2 The arithmetic operators consist of addition +, subtraction -, multiplication *, division /, and remainder %. An arithmetic operation that uses two int values will evaluate to an int value. An arithmetic operation that uses at least one double value will evaluate to a double value.
      • Exclusion statement: Expressions that result in special double values (e.g., infinities and NaN) are outside the scope of the AP Computer Science A course and exam.
    • 1.3.C.3 When dividing numeric values that are both int values, the result is only the integer portion of the quotient. When dividing numeric values that use at least one double value, the result is the quotient.
    • 1.3.C.4 The remainder operator % is used to compute the remainder when one number a is divided by another number b.
      • Exclusion statement: The use of values less than 0 for a and the use of values less than or equal to 0 for b is outside the scope of the AP Computer Science A course and exam.
    • 1.3.C.5 Operators can be used to construct compound expressions. At compile time, numeric values are associated with operators according to operator precedence to determine how they are grouped. Parentheses can be used to modify operator precedence. Multiplication, division, and remainder have precedence over addition and subtraction. Operators with the same precedence are evaluated from left to right.
    • 1.3.C.6 An attempt to divide an integer by the integer zero will result in an ArithmeticException.
      • Exclusion statement: The use of dividing by zero when one numeric value is a double is outside the scope of the AP Computer Science A course and exam.
    עברית

    מטרת למידה 1.3.A: פיתוח קוד ליצירת תפוקה וקביעת התוצאה שתוצג.

    • 1.3.A.1 System.out.print וSystem.out.println מציגים מידע על מסך המחשב. System.out.println מעביר את המעבר לסיבה חדשה לאחר הצגת המידע, בעוד שSystem.out.print אינו עושה זאת.

    מטרת למידה 1.3.B: פיתוח קוד לשימוש בליטרלים של מחרוזות וקביעת התוצאה של שימוש בליטרלים אלו.

    • 1.3.B.1 ליטרל הוא הייצוג הקודי של ערך קבוע.
    • 1.3.B.2 ליטרל מחרוזת הוא רצף של תווים הכולא בתוך סימני ציטוט כפולים.
    • 1.3.B.3 רצפי בריחה הם רצפים מיוחדים של תווים שיכולים להיות כלולים במחרוזת. הם מתחילים ב\ ול他们有 משמעות מיוחדת ב-Java. רצפי הבריחה המשמשים בקורס זה כוללים סימן ציטוט כפול \", מקש חזרה (backslash) \\, וסיבת חדשה (newline) \n.

    מטרת למידה 1.3.C: פיתוח קוד עבור ביטויים אריתמטיים וקביעת התוצאה של ביטויים אלו.

    • 1.3.C.1 ביטויים אריתמטיים, המורכבים מערכים מספריים, משתנים ומפעולות, כוללים ביטויים מסוג int וdouble.
    • 1.3.C.2 הפעולות האריתמטיות כוללות חיבור +, חיסור -, כפל *, חלוקה /, ושארית %. פעולה אריתמטית שמשתמשת בשני ערכי int תוביל לתוצאה של ערך int. פעולה אריתמטית שמשתמשת לפחות בערך אחד מסוג double תוביל לתוצאה של ערך double.
      • הצהרת יציא: ביטויים המובילים לערכי double מיוחדים (למשל, אינסופיים ו-NaN) אינם בטווח הלימודים ובחינה של AP Computer Science A.
    • 1.3.C.3 כאשר מחלקים ערכים מספריים שהם שניהם ערכי int, התוצאה היא רק החלק השלם של המנה. כאשר מחלקים ערכים מספריים שמשתמשים בהם לפחות בערך אחד מסוג double, התוצאה היא המנה.
    • 1.3.C.4 הפעולת שארית % משמשת לחישוב השארית כאשר מספר a מחולק במספר אחר b.
      • הצהרת יציא: השימוש בערכים קטנים מ0 עבור a והשימוש בערכים קטנים או שווים ל0 עבור b אינם בטווח הלימודים ובחינה של AP Computer Science A.
    • 1.3.C.5 ניתן להשתמש בפעולות לבניית ביטויים מורכבים. בזמן ההרכבה, ערכים מספריים מקושרים לפעולות בהתאם לסדר עדיפות של פעולות כדי לקבוע כיצד הם מקושרים. סוגריים יכולים לשמש לשינוי סדר עדיפות של פעולות. כפל, חלוקה ושארית ישנם עדיפות על פני חיבור וחיסור. פעולות עם אותה עדיפות מוערכות משמאל לימין.
    • 1.3.C.6 ניסיון לחלק מספר שלם באפס שלם יוביל לArithmeticException.
      • הצהרת יציא: השימוש בחלוקה לאפס כאשר ערך מספרי אחד הוא double אינו בטווח הלימודים ובחינה של AP Computer Science A.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    An expression 表达式 combines values and operators to compute a result: + - * / and % (modulus 取模, the remainder). Integer division truncates: 7 / 2 is 3, while 7 % 2 is 1. Operator precedence follows math (*,/,% before +,-). Print with:

    System.out.print("no newline");
    System.out.println("with newline");
    

    Dividing an integer by the integer 0 (like 7 / 0) is not allowed and crashes at run time with an ArithmeticException. Inside a string, a backslash marks an escape sequence 转义序列: \" prints a double quote, \\ a single backslash, and \n starts a new line – so System.out.println("She said \"hi\""); prints She said "hi".

    Explore · ⁨חקור⁩

    Explore the order of operations step by step · ⁨חקרו את סדר הפעולות צעד אחר צעד⁩

    Java applies *, /, % before + and -, working left to right. Watch each step and see why 2 + 3 * 4 is $14$, not $20$ — the multiplication happens first. · ⁨Java מפעילה *, /, % לפני + ו -, פועלת משמאל לימין. צפו בכל שלב ותראו מדוע 2 + 3 * 4 היא $14$, ולא $20$ — הכפל מתבצע תחילה.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    expression/ekˈspreʃn/ ביטוי
    modulus/ˈmɒdjʊləs/ מודולוס
    escape sequence/eˈskeɪp ˈsiːkwəns/ תווית בריחה
    1.4

    Assignment Statements and Input

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.4.A: Develop code for assignment statements with expressions and determine the value that is stored in the variable as a result of these statements.

    • 1.4.A.1 Every variable must be assigned a value before it can be used in an expression. That value must be from a compatible data type. A variable is initialized the first time it is assigned a value. Reference types can be assigned a new object or null if there is no object. The literal null is a special value used to indicate that a reference is not associated with any object.
    • 1.4.A.2 The assignment operator = allows a program to initialize or change the value stored in a variable. The value of the expression on the right is stored in the variable on the left.
      • Exclusion statement: The use of assignment operators inside expressions (e.g., a = b = 4; or a[i += 5]) is outside the scope of the AP Computer Science A course and exam.
    • 1.4.A.3 During execution, an expression is evaluated to produce a single value. The value of an expression has a type based on the evaluation of the expression.

    Learning Objective 1.4.B: Develop code to read input.

    • 1.4.B.1 Input can come in a variety of forms, such as tactile, audio, visual, or text. The Scanner class is one way to obtain text input from the keyboard.
      • Exclusion statement: Any specific form of input from the user is outside the scope of the AP Computer Science A course and exam.
    עברית

    מטרת למידה 1.4.A: פיתוח קוד עבור הוראות הצבה עם ביטויים וקביעת הערך שנשמר במשתנה כתוצאה מההוראות הללו.

    • 1.4.A.1 לכל משתנה יש להעריך ערך לפני שהוא יכול לשמש בביטוי. ערך זה חייב להיות מסוג נתונים תואם. משתנה מוזן לראשונה כשהוא מקבל ערך. סוגי ייחוס יכולים לקבל אובייקט חדש או null אם אין אובייקט. הליטרל null הוא ערך מיוחד המשמש להצגה שהייחוס אינו קשור לאובייקט כלשהו.
    • 1.4.A.2 פעולת ההצבה = מאפשרת לתוכנית לזין או לשנות את הערך הנשמר במשתנה. ערך הביטוי בצד ימין נשמר במשתנה בצד שמאל.
      • הערת פסילה: השימוש בפועלי ההשמה בתוך ביטויים (למשל, a = b = 4; או a[i += 5]) אינם כלל שיעורי הקורס ובמבחן AP Computer Science A.
    • 1.4.A.3 במהלך ביצוע, ביטוי מוערך כדי לייצר ערך יחיד. לערך הביטוי יש סוג המבוסס על הערכת הביטוי.

    מטרה לימודית 1.4.B: פיתוח קוד לקריאת קלט.

    • 1.4.B.1 הקלט יכול לבוא בצורות שונות, כגון מגע, שמיעה, חזות או טקסט. המחלקה Scanner היא אחת הדרכים להשיג קלט טקסט מהמקלדת.
      • הצהרת בלילה: כל צורה ספציפית של קלט מהמשתמש אינה בתחום ההשכלה של קורס ובחינת AP Computer Science A.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    An assignment 赋值 x = expr; evaluates the right side and stores it in the left variable. Read input with a Scanner:

    Scanner in = new Scanner(System.in);
    int age = in.nextInt();
    String name = in.next();
    
    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    assignment/əˈsaɪnmənt/ הקצה
    1.5

    Casting and Range of Variables

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.5.A: Develop code to cast primitive values to different primitive types in arithmetic expressions and determine the value that is produced as a result.

    • 1.5.A.1 The casting operators (int) and (double) can be used to convert from a double value to an int value (or vice versa).
    • 1.5.A.2 Casting a double value to an int value causes the digits to the right of the decimal point to be truncated.
    • 1.5.A.3 Some code causes int values to be automatically cast (widened) to double values.
    • 1.5.A.4 Values of type double can be rounded to the nearest integer by (int)(x + 0.5) for non-negative numbers or (int)(x - 0.5) for negative numbers.

    Learning Objective 1.5.B: Describe conditions when an integer expression evaluates to a value out of range.

    • 1.5.B.1 The constant Integer.MAX_VALUE holds the value of the largest possible int value. The constant Integer.MIN_VALUE holds the value of the smallest possible int value.
    • 1.5.B.2 Integer values in Java are represented by values of type int, which are stored using a finite amount (4 bytes) of memory. Therefore, an int value must be in the range from Integer.MIN_VALUE to Integer.MAX_VALUE inclusive.
    • 1.5.B.3 If an expression would evaluate to an int value outside of the allowed range, an integer overflow occurs. The result is an int value in the allowed range but not necessarily the value expected.

    Learning Objective 1.5.C: Describe conditions that limit accuracy of expressions.

    • 1.5.C.1 Computers allot a specified amount of memory to store data based on the data type. If an expression would evaluate to a double that is more precise than can be stored in the allotted amount of memory, a round-off error occurs. The result will be rounded to the representable value. To avoid rounding errors that naturally occur, use int values.
      • Exclusion statement: Other special decimal data types that can be used to avoid rounding errors are outside the scope of the AP Computer Science A course and exam.
    עברית

    מטרה לימודית 1.5.A: פיתוח קוד לביצוע Cast של ערכים פרמיטיביים לסוגים פרמיטיביים שונים בביטויים אריתמטיים והגדרת הערך הנובע כתוצאה מכך.

    • 1.5.A.1 אופרטורי ה-Cast (int) ו-(double) יכולים לשמש להמרה מערך מסוג double לערך מסוג int (או להפך).
    • 1.5.A.2 ביצוע Cast של ערך מסוג double לערך מסוג int גורם לגיליות מימין לנקודת העשרון להיות נחתכות.
    • 1.5.A.3 חלק מהקוד גורם לערכי int להיות מומרים (Widened) באופן אוטומטי לערכי double.
    • 1.5.A.4 ערכים מסוג double יכולים לעבור עיגול למספר השלם הקרוב ביותר על ידי (int)(x + 0.5) עבור מספרים לא שליליים או (int)(x - 0.5) עבור מספרים שליליים.

    מטרה לימודית 1.5.B: תיאור תנאים שבהם ביטוי שלם מתערך לערך מחוץ לטווח המותר.

    • 1.5.B.1 הקבוע Integer.MAX_VALUE מכיל את הערך של ערך int המקסימלי האפשרי. הקבוע Integer.MIN_VALUE מכיל את הערך של ערך int המינימלי האפשרי.
    • 1.5.B.2 ערכים שלמים ב-Java מיוצגים על ידי ערכים מסוג int, אשר מאוחזים בכמות מוגבלת (4 BYTES) של זיכרון. לכן, ערך מסוג int חייב להיות בטווח מ-Integer.MIN_VALUE עד Integer.MAX_VALUE כולל.
    • 1.5.B.3 אם ביטוי היה מתערך לערך מסוג int מחוץ לטווח המותר, מתרחש Overflow של שלמים. התוצאה היא ערך מסוג int בטווח המותר אך לא בהכרח הערך הצפוי.

    מטרה לימודית 1.5.C: תיאור תנאים המגבילים את הדיוק של ביטויים.

    • 1.5.C.1 מחשבים מקצים כמות מוגדרת של זיכרון לאחסון נתונים בהתבסס על סוג הנתונים. אם ביטוי היה מתערך לערך מסוג double שדיוקו גדול יותר ממה שניתן לאחסן בכמות הזיכרון המוקצה, מתרחש טעות עיגול. התוצאה תועגל לערך הניתן לייצוג. כדי למנוע טעויות עיגול שמתרחשות באופן טבעי, השתמשו בערכי int.
      • הצהרת בלילה: סוגי נתוני עשרון מיוחדים אחרים שניתן להשתמש בהם כדי למנוע טעויות עיגול הם מחוץ לתחום ההשכלה של קורס ובחינת AP Computer Science A.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    int range, overflow and truncation

    Each type has a fixed range; an int overflows past about 2.1 billion. Casting 类型转换 converts between types. Widening (int to double) is automatic; narrowing needs an explicit cast, which truncates (does not round):

    double avg = (double) total / count;   // force real division
    int whole = (int) 3.9;                 // 3, truncated
    

    Exam skill: watch for integer division producing a truncated result when a decimal was expected – cast one operand to double first.

    Worked example. Trace each expression:

    • 7 / 2 → 3 (both int, so division truncates);
    • 7.0 / 2 → 3.5 (one double forces real division);
    • 7 % 2 → 1 (the remainder);
    • (double) 7 / 2 → 3.5 (the cast binds tighter than /, so it is 7.0 / 2);
    • (double) (7 / 2) → 3.0 (the parentheses compute 7 / 2 = 3 in int first, then widen).

    The last two look alike but differ – the position of the cast decides whether the truncation happens.

    Explore · ⁨חקור⁩

    Why int and double store numbers differently · ⁨מדוע int ו double מאחסנים מספרים בצורה שונה⁩

    An int holds only whole numbers in a fixed range; a double stores a mantissa and an exponent, trading exactness for a huge range. Casting double→int throws away the fraction, and a value past an int's range overflows. · ⁨int מכיל רק מספרים שלמים בטווח קבוע; double אוסף סימן ומעריך, מחליף דיוק בטווח עצום. ההמרה double→int מזהרת את השבר, וערך מעבר לטווח של int יגרום לגלישה.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Casting/ˈkæstɪŋ/ יציקה
    1.6

    Compound Assignment Operators

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.6.A: Develop code for assignment statements with compound assignment operators and determine the value that is stored in the variable as a result.

    • 1.6.A.1 Compound assignment operators +=, -=, *=, /=, and %= can be used in place of the assignment operator in numeric expressions. A compound assignment operator performs the indicated arithmetic operation between the value on the left and the value on the right and then assigns the result to the variable on the left.
    • 1.6.A.2 The post-increment operator ++ and post-decrement operator -- are used to add 1 or subtract 1 from the stored value of a numeric variable. The new value is assigned to the variable.
      • Exclusion statement: The use of increment and decrement operators in prefix form (e.g., ++x) is outside the scope of the AP Computer Science A course and exam. The use of increment and decrement operators inside other expressions (e.g., arr[x++]) is outside the scope of the AP Computer Science A course and exam.
    עברית

    מטרה לימודית 1.6.A: פיתוח קוד לחישובי השמה עם אופרטורי השמה מורכבים והגדרת הערך המאוחסן במשתנה כתוצאה מכך.

    • 1.6.A.1 פועלי השמה מורכבים +=, -=, *=, /= ו-%= יכולים לשמש במקום פועל ההשמה בביטויים נומריים. פועל השמה מורכב מבצע את פעולת האריתמטיקה המצוינת בין הערך בשמאל לערך בימין ולאחר מכן משמיר את התוצאה במשתנה שבשמאל.
    • 1.6.A.2 מפעיל ההגדלה ה-Post-increment (++) ומפעיל ההקטנה ה-Post-decrement (--) משמשים להוספת 1 או לחיסור 1 מערך המאוחסן במשתנה מספרי. הערך החדש מוקנה למשתנה.
      • הצהרת חריגה: השימוש במפעילי הגדלה והקטנה בצורת פריפיקס (למשל, ++x) אינם בטווח לימודי הקורס ובמבחן AP Computer Science A. שימוש במפעילי הגדלה והקטנה בתוך ביטויים אחרים (למשל, arr[x++]) אינם בטווח לימודי הקורס ובמבחן AP Computer Science A.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Shorthands combine an operation with assignment: x += 5 means x = x + 5; likewise -=, *=, /=, %=. The increment and decrement operators x++ and x-- add or subtract one.

    1.7

    Application Program Interface (API) and Libraries

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.7.A: Identify the attributes and behaviors of a class found in the libraries contained in an API.

    • 1.7.A.1 Libraries are collections of classes. An application programming interface (API) specification informs the programmer how to use those classes. Documentation found in API specifications and libraries is essential to understanding the attributes and behaviors of a class defined by the API. A class defines a specific reference type. Classes in the APIs and libraries are grouped into packages. Existing classes and class libraries can be utilized to create objects.
    • 1.7.A.2 Attributes refer to the data related to the class and are stored in variables. Behaviors refer to what instances of the class can do (or what can be done with them) and are defined by methods.
    עברית

    יעד הלמידה 1.7.A: זיהוי מאפיינים והתנהגויות של מחלקה הנמצאים בספריות הכוללות API.

    • 1.7.A.1 ספריות הן קבוצות של מחלקות. ספציפיקציה של ממשק תוכנת אפליקציה (API) מכוונת את המתכנן כיצד להשתמש במחלקות אלו. מסמך המצוי בספציפיקציות של API ובספריות הוא קריטי להבנת המאפיינים וההתנהגויות של מחלקה שהוגדרה על ידי ה-API. מחלקה מגדירה סוג הפניה ספציפי. מחלקות ב-API ובספריות מסודרות בקבוצות (packages). ניתן להשתמש במחלקות ובספריות מחלקות קיימות ליצירת אובייקטים.
    • 1.7.A.2 מאפיינים מתייחסים לנתונים הקשורים למחלקה ואחסונים במשתנים. התנהגויות מתייחסות לכמה שמוצגים (instances) של המחלקה יכולים לעשות (או מה ניתן לבצע עמם), והן מוגדרות על ידי מתודות.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    An API (Application Programming Interface) 应用程序接口 is the published list of classes and methods you may use. A library 库 is a collection of ready-made classes (like Math, String, Scanner). You read the API documentation to learn what a method needs (its parameters) and returns, without seeing its inner code – an example of abstraction 抽象.

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    library/ˈlaɪbrəri/ ספרייה
    abstraction/əbˈstrækʃn/ הפשטה
    Interface/ˈɪntəfeɪs/ ממשק
    1.8

    Documentation with Comments

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.8.A: Describe the functionality and use of code through comments.

    • 1.8.A.1 Comments are written for both the original programmer and other programmers to understand the code and its functionality, but are ignored by the compiler and are not executed when the program is run. Three types of comments in Java include /* */, which generates a block of comments; //, which generates a comment on one line; and /** */, which are Javadoc comments and are used to create API documentation.
    • 1.8.A.2 A precondition is a condition that must be true just prior to the execution of a method in order for it to behave as expected. There is no expectation that the method will check to ensure preconditions are satisfied.
    • 1.8.A.3 A postcondition is a condition that must always be true after the execution of a method. Postconditions describe the outcome of the execution in terms of what is being returned or the current value of the attributes of an object.
    עברית

    יעד הלמידה 1.8.A: תיאור הפונקציונליות והשימוש בקוד באמצעות הערות.

    • 1.8.A.1 הערות נכתבות עבור המתכנן המקורי ועבור מתכננים אחרים כדי להבין את הקוד ותפקודו, אך הן מוהדרות על ידי המترגם ואינן מופעות כאשר התוכנית מופעלת. שלושה סוגי הערות ב-Java כוללים: /* */, שמייצר בלוק של הערות; //, שמייצר הערה בשורה אחת; ו-/** */, שהן הערות Javadoc המשמשות ליצירת מסמכי API.
    • 1.8.A.2 תנאי מקדים הוא תנאי שחייב להיות נכון בדיוק לפני ביצוע מתודה כדי שתתנהג כצפוי. אין ציפייה שהמתודה תבדוק כדי לוודא שתנאים מקדימים מלאים.
    • 1.8.A.3 תנאי בוא הוא תנאי שחייב להיות תמיד נכון לאחר ביצוע מתודה. תנאי בוא מתארים את התוצאה של הביצוע בהתאם למה שנחזר או הערך הנוכחי של המאפיינים של אובייקט.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Comments 注释 are ignored by the compiler but explain code to humans: // for a single line, /* ... */ for a block, and /** ... */ for a Javadoc comment that documents a method's purpose, parameters, and return value. Precise preconditions and postconditions are written here.

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Comments/ˈkɒments/ הערות
    1.9

    Method Signatures

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.9.A: Identify the correct method to call based on documentation and method signatures.

    • 1.9.A.1 A method is a named block of code that only runs when it is called. A block of code is any section of code that is enclosed in braces. Procedural abstraction allows a programmer to use a method by knowing what the method does even if they do not know how the method was written.
    • 1.9.A.2 A parameter is a variable declared in the header of a method or constructor and can be used inside the body of the method. This allows values or arguments to be passed and used by a method or constructor. A method signature for a method with parameters consists of the method name and the ordered list of parameter types. A method signature for a method without parameters consists of the method name and an empty parameter list.

    Learning Objective 1.9.B: Describe how to call methods.

    • 1.9.B.1 A void method does not have a return value and is therefore not called as part of an expression.
    • 1.9.B.2 A non-void method returns a value that is the same type as the return type in the header. To use the return value when calling a non-void method, it must be stored in a variable or used as part of an expression.
    • 1.9.B.3 An argument is a value that is passed into a method when the method is called. The arguments passed to a method must be compatible in number and order with the types identified in the parameter list of the method signature. When calling methods, arguments are passed using call by value. Call by value initializes the parameters with copies of the arguments.
    • 1.9.B.4 Methods are said to be overloaded when there are multiple methods with the same name but different signatures.
    • 1.9.B.5 A method call interrupts the sequential execution of statements, causing the program to first execute the statements in the method before continuing. Once the last statement in the method has been executed or a return statement is executed, the flow of control is returned to the point immediately following where the method was called.
    עברית

    יעד הלמידה 1.9.A: זיהוי המתודה הנכונה לקריאה על בסיס מסמכות וחתימות מתודות.

    • 1.9.A.1 מתודה היא בלוק קוד בעל שם המופעל רק כאשר היא נקראת. בלוק קוד הוא כל חלק מקוד המוקף בסוגריים. הפשטה הליכה מאפשרת למתכנן להשתמש במתודה על ידי ידע על מה שהיא עושה, גם אם לא יודע איך הכתובה.
    • 1.9.A.2 פרמטר הוא משתנה המוגדר בחתימת המתודה או הבונה וניתן להשתמש בו בתוך גוף המתודה. הדבר מאפשר העברת ערכים או ארגומנטים לשימוש על ידי מתודה או בונה. חתימת מתודה למתודה עם פרמטרים מורכבת משם המתודה ורשימה מסודרת של סוגי הפרמטרים. חתימת מתודה למתודה ללא פרמטרים מורכבת משם המתודה ורשימת פרמטרים ריקה.

    יעד הלמידה 1.9.B: תיאור כיצד לקרוא מתודות.

    • 1.9.B.1 מתודה void אינה מחזירה ערך ולכן אינה נקראת כחלק מביטוי.
    • 1.9.B.2 מתודה שאינה void מחזירה ערך זהה לסוג ההחזרה בחתימת המתודה. כדי להשתמש בערך ההחזרה בעת קריאה למתודה שאינה void, יש לאחסנו במשתנה או להשתמש בו כחלק מביטוי.
    • 1.9.B.3 ארגומנט הוא ערך שעובר לתוך מתודה בעת קריאתה. הארגומנטים שעוברים למתודה חייבים להיות תואמים במספרם ובסדרם לסוגים המזהים ברשימת הפרמטרים בחתימת המתודה. בעת קריאת מתודות, ארגומנטים עוברים באמצעות קריאה על ידי ערך. קריאה על ידי ערך מאפסת את הפרמטרים עם העתקים של הארגומנטים.
    • 1.9.B.4 אומרים ששיטות הן עמוסות (overloaded) כאשר קיימות מספר שיטות בעלות אותו שם אך חתימות שונות.
    • 1.9.B.5 קריאת שיטה מפסיקה את הביצוע הסדרתי של פקודות, וגורמת לתוכנה לבצע תחילה את הפקודות בתוך השיטה לפני שהיא ממשיכה. ברגע ביצועה של הפקודה האחרונה בשיטה או ביצוע פקודת החזרה, זרימת הבקרה חוזרת לנקודה המיידית שלאחר מקום קריאת השיטה.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    A method signature 方法签名 is a method's name plus its parameter types, e.g. nextInt() or substring(int, int). To call a method you must supply arguments 实参 that match the parameters in number, type, and order. The method header (the full declaration) also states the return type – the type of value the method gives back (void if none) – but the return type is not part of the signature, which is why two methods cannot differ by return type alone.

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    method signature/ˈmeθəd ˈsɪɡnɪtʃə/ חתימת שיטה
    arguments/ˈɑːɡjuːmənts/ ארגומנטים
    1.10

    Calling Class Methods

    Syllabus · ⁨סיילבוס⁩
    Learning ObjectiveEssential Knowledge

    1.10.A
    Develop code to call class methods and determine the result of those calls.

    • 1.10.A.1 Class methods are associated with the class, not instances of the class. Class methods include the keyword static in the header before the method name.
    • 1.10.A.2 Class methods are typically called using the class name along with the dot operator. When the method call occurs in the defining class, the use of the class name is optional in the call.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    A class (static) method 类方法 belongs to the class itself, so you call it on the class name: ClassName.method(args). No object is needed.

    Explore · ⁨חקור⁩

    Follow a class-method call on the stack · ⁨עקבו אחרי קריאת שיטה בקלאס על הערימה⁩

    Calling a class method like Math.max pushes a new frame onto the call stack; when the method returns a value, its frame pops and control goes back to the caller. Step through to watch the stack grow and shrink. · ⁨קריאה לשיטת קלאס כמו Math.max דוחפת מסגרת חדשה לערימת הקריאות; כאשר השיטה חוזרת ערך, המסגרת שלה נשלפת והשליטה חוזרת לקורא. צעדו כדי לצפות בערימה גדלה וקטנה.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    class (static) method/klæs ˈmeθəd/ שיטת מחלקה (סטטית)
    1.11

    Math Class

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.11.A: Develop code to write expressions that incorporate calls to built-in mathematical libraries and determine the value that is produced as a result.

    • 1.11.A.1 The Math class is part of the java.lang package. Classes in the java.lang package are available by default.
    • 1.11.A.2 The Math class contains only class methods. The following Math class methods—including what they do and when they are used—are part of the Java Quick Reference:
      • static int abs(int x) returns the absolute value of an int value.
      • static double abs(double x) returns the absolute value of a double value.
      • static double pow(double base, double exponent) returns the value of the first parameter raised to the power of the second parameter.
      • static double sqrt(double x) returns the nonnegative square root of a double value.
      • static double random() returns a double value greater than or equal to 0.0 and less than 1.0.
    • 1.11.A.3 The values returned from Math.random() can be manipulated using arithmetic and casting operators to produce a random int or double in a defined range based on specified criteria. Each endpoint of the range can be inclusive, meaning the value is included, or exclusive, meaning the value is not included.
    עברית

    מטרת הלמידה 1.11.A: פיתוח קוד לכתיבת ביטויים המכילים קריאות לספריות מתמטיות מובנות וקביעת הערך שמיוצר כתוצאה.

    • 1.11.A.1 מחלקת Math היא חלק מארזת java.lang. מחלקות בארזת java.lang זמינות ברירת מחדל.
    • 1.11.A.2 מחלקת Math מכילה רק שיטות מחלקה. שיטות מחלקת Math הבאות—כולל תיאור הפעולה שלהן ומתי הן משמשות—נכללות בהפניה מהירה ל-Java:
      • static int abs(int x) מחזירה את הערך המוחלט של ערך int.
      • static double abs(double x) מחזירה את הערך המוחלט של ערך double.
      • static double pow(double base, double exponent) מחזירה את ערך הפרמטר הראשון מוועד למעלה בדרגה השנייה.
      • static double sqrt(double x) מחזירה את השורש הריבועי האי-שלילי של ערך double.
      • static double random() מחזירה ערך double הגדול או שווה ל0.0 וקטן מ1.0.
    • 1.11.A.3 ניתן לעבד את הערכים המוחזרים מתוך Math.random() באמצעות פעולות אריתמטיות והמרה (casting) כדי ליצור מספר מקרי int או double בטווח מוגדר על פי קריטריונים ספציפיים. כל אחת מקצוות הטווח יכולה להיות סגורה (inclusive), כלומר הערך נכלל, או פתוחה (exclusive), כלומר הערך אינו נכלל.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    The Math class provides static math methods: Math.abs(x), Math.pow(base, exp), Math.sqrt(x), and Math.random() (a double in $[0,1)$). To get a random integer from 0 to n-1: (int)(Math.random() * n).

    1.12

    Objects: Instances of Classes

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.12.A: Explain the relationship between a class and an object.

    • 1.12.A.1 An object is a specific instance of a class with defined attributes. A class is the formal implementation, or blueprint, of the attributes and behaviors of an object.
    • 1.12.A.2 A class hierarchy can be developed by putting common attributes and behaviors of related classes into a single class called a superclass. Classes that extend a superclass, called subclasses, can draw upon the existing attributes and behaviors of the superclass without replacing these in the code. This creates an inheritance relationship from the subclasses to the superclass.
      • Exclusion statement: Designing and implementing inheritance relationships are outside the scope of the AP Computer Science A course and exam.
    • 1.12.A.3 All classes in Java are subclasses of the Object class.

    Learning Objective 1.12.B: Develop code to declare variables to store reference types.

    • 1.12.B.1 A variable of a reference type holds an object reference, which can be thought of as the memory address of that object.
    עברית

    מטרת למידה 1.12.A: הסבר הקשר בין מחלקה לאובייקט.

    • 1.12.A.1 אובייקט הוא instance ספציפי של מחלקה עם מאפיינים מוגדרים. מחלקה היא היישום הרשמי, או התוכנית האדריכלית (blueprint), של המאפיינים וההתנהגויות של אובייקט.
    • 1.12.A.2 היררכיה של מחלקות יכולה לפתח על ידי הכנסת מאפיינים והתנהגויות משותפים של מחלקות קשורות למחלקה אחת הנקראת מחלקת על (superclass). מחלקות המרחיבות מחלקת על, הנקראות מחלקות תת (subclasses), יכולות להסתמך על המאפיינים וההתנהגויות הקיימים של המחלקת העל ללא החלפתם בקוד. יוצר זאת יחס ירשה (inheritance relationship) ממחלקות התת אל המחלקת העל.
      • הערה: עיצוב ויישום של יחסי ירשה חוצים מגבלות תוכן הקורס ובחינת AP Computer Science A.
    • 1.12.A.3 כל המחלקות ב-Java הן מחלקות תת של מחלקת Object.

    מטרת למידה 1.12.B: פיתוח קוד להצהרת משתנים לאחסון סוגי עזרה (reference types).

    • 1.12.B.1 משתנה מסוג עזרה מחזיק רפרנס לאובייקט, שמעלה ככיוון זיכרון של האובייקט הזה.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    = copies the reference, not the object

    A class 类 is a blueprint; an object 对象 is a concrete instance 实例 built from it. A class bundles data (fields) with behavior (methods) – the heart of object-oriented programming 面向对象编程. String, Scanner, and ArrayList are all classes you instantiate.

    Classes can be organised into a hierarchy. A superclass 父类 holds attributes and behaviors shared by several subclasses 子类 that extend it – an inheritance relationship 继承关系. Every class in Java is ultimately a subclass of the built-in Object class, which is why every object already has a toString method; writing a subclass method with the same signature as a superclass one is method overriding 方法重写. (Designing your own inheritance is beyond this course, but you are expected to recognise this vocabulary.)

    A class diagram: private attributes and public methods
    A class diagram: private attributes and public methods
    A class is a blueprint; each object is one instance built from it
    A class is a blueprint; each object is one instance built from it
    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    class/klæs/ כיתה
    object/ˈɒbdʒekt/ אובייקט
    instance/ˈɪnstəns/ תעודת ייצוג
    object-oriented programming/ˈɒbdʒekt ˈɔːrɪəntɪd ˈprəʊɡræmɪŋ/ תכנות ממוקד-אובייקטים
    superclass/ˈsuːpəklæs/ סוג אב
    subclasses/ˈsʌbklæsɪz/ מחלקות בת
    inheritance relationship/ɪnˈherɪtəns rɪˈleɪʃənʃɪp/ יחס ירוש
    method overriding/ˈmeθəd ˌəʊvəˈraɪdɪŋ/ החלפת שיטות
    1.13

    Object Creation and Storage (Instantiation)

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.13.A: Identify, using its signature, the correct constructor being called.

    • 1.13.A.1 A class contains constructors that are called to create objects. They have the same name as the class.
    • 1.13.A.2 A constructor signature consists of the constructor's name, which is the same as the class name, and the ordered list of parameter types. The parameter list, in the header of a constructor, lists the types of the values that are passed and their variable names.
    • 1.13.A.3 Constructors are said to be overloaded when there are multiple constructors with different signatures.

    Learning Objective 1.13.B: Develop code to declare variables of the correct types to hold object references.

    • 1.13.B.1 A variable of a reference type holds an object reference or, if there is no object, null.

    Learning Objective 1.13.C: Develop code to create an object by calling a constructor.

    • 1.13.C.1 An object is typically created using the keyword new followed by a call to one of the class's constructors.
    • 1.13.C.2 Parameters allow constructors to accept values to establish the initial values of the attributes of the object.
    • 1.13.C.3 A constructor argument is a value that is passed into a constructor when the constructor is called. The arguments passed to a constructor must be compatible in order and number with the types identified in the parameter list in the constructor signature. When calling constructors, arguments are passed using call by value. Call by value initializes the parameters with copies of the arguments.
    • 1.13.C.4 A constructor call interrupts the sequential execution of statements, causing the program to first execute the statements in the constructor before continuing. Once the last statement in the constructor has been executed, the flow of control is returned to the point immediately following where the constructor was called.
    עברית

    מטרת למידה 1.13.A: זיהוי, באמצעות הסיגnature שלו, הבונה (constructor) הנכון שנקרא.

    • 1.13.A.1 למחלקה ישנם בונים (constructors) הנקראים ליצירת אובייקטים. הם נושאים את אותו שם כמו המחלקה.
    • 1.13.A.2 סיגnature של בונה מורכב משם הבונה, שהוא אותו שם כמו שם המחלקה, ורשימה מסודרת של סוגי הפרמטרים. רשימת הפרמטרים, בתוך הכותרת של הבונה, מפרטת את סוגי הערכים שעוברים ואת שמות המשתנים שלהם.
    • 1.13.A.3 בונים נחשבים כ" overloaded " (מועמסים מחדש) כאשר קיימים מספר בונים עם סיגnature שונים.

    מטרת למידה 1.13.B: פיתוח קוד להכרזת משתנים בעלי סוגים נכונים כדי לאחסן רעיונות (references) של אובייקטים.

    • 1.13.B.1 משתנה מסוג רעיון (reference type) אחסן רעיון של אובייקט או, אם אין אובייקט, null.

    מטרת למידה 1.13.C: פיתוח קוד ליצירת אובייקט על ידי קריאה לבונה (constructor).

    • 1.13.C.1 אובייקט נוצר בדרך כלל באמצעות המילה המפתחית new שבהמשך נעשה קריאה לאחד הבונים של המחלקה.
    • 1.13.C.2 פרמטרים מאפשרים לבונים לקבל ערכים כדי לקבוע את הערכים ההתחלתיים של המאפיינים של האובייקט.
    • 1.13.C.3 פרמטר כניסה לבונה הוא ערך שמעבירים לתוך בונה כאשר הבונה נקרא. הפרמטרים שנעברים לבונה חייבים להיות תואמים בסדר ובמספר לסוגים שזוהו ברשימת הפרמטרים בחתימת הבונה. בעת קריאת בונים, פרמטרים מועברים באמצעות "קריאה בערך" (call by value). קריאה בערך מזינה את הפרמטרים עם העתקים של הפרמטרים הנעברים.
    • 1.13.C.4 קריאת בונה מפסיקה את הביצוע הסדרתי של הפקודות, וגורמת לתוכנית לבצע תחילה את הפקודות שבבונה לפני שהיא ממשיכה. לאחר ביצוע הפקודה האחרונה בבונה, זרימת הביצוע חוזרת לנקודה המיישירה אחרי מקום הקריאה לבונה.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Instantiation 实例化 creates an object with the new keyword, which calls a constructor 构造函数:

    Scanner in = new Scanner(System.in);
    String s = new String("hi");   // or just "hi"
    

    The variable holds a reference 引用 (the object's address), not the object itself. Two references can point to the same object; comparing them with == compares addresses, not contents.

    A reference can also point to nothing: the special value null 空值 means "not attached to any object". Calling a method on a null reference crashes at run time with a NullPointerException. Guard against it by testing with ==/!= and checking null first, so && short-circuits before the method runs: if (s != null && s.length() > 0).

    A primitive variable holds its value directly, a reference holds an arrow to the object
    A primitive variable holds its value directly, a reference holds an arrow to the object
    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Instantiation/ˌɪnstænʃɪˈeɪʃn/ יצירת אובייקטים
    constructor/kənˈstrʌktə/ בונה
    reference/ˈrefrəns/ יחוס
    null/nʌl/ ערך ריק (null)
    1.14

    Calling Instance Methods

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 1.14.A: Develop code to call instance methods and determine the result of these calls.

    • 1.14.A.1 Instance methods are called on objects of the class. The dot operator is used along with the object name to call instance methods.
    • 1.14.A.2 A method call on a null reference will result in a NullPointerException.
    עברית

    מטרת למידה 1.14.A: פיתוח קוד לקריאת שיטות אינסטנציה וקביעת התוצאה של קריאות אלו.

    • 1.14.A.1 שיטות אינסטנציה נקראות על אובייקטים של המחלקה. האופרטור הנקודה (dot operator) משמש יחד עם שם האובייקט כדי לקרוא לשיטות אינסטנציה.
    • 1.14.A.2 קריאת שיטה על רעיון (reference) מסוג null תוביל ל-NullPointerException.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    An instance method 实例方法 acts on a specific object, so you call it on the object reference: object.method(args). Example: in.nextInt(), word.length().

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    instance method/ˈɪnstəns ˈmeθəd/ שיטת אובייקט
    1.15

    String Manipulation

    Syllabus · ⁨סיילבוס⁩
    Learning ObjectiveEssential Knowledge

    1.15.A
    Develop code to create string objects and determine the result of creating and combining strings.

    • 1.15.A.1 A String object represents a sequence of characters and can be created by using a string literal or by calling the String class constructor.
    • 1.15.A.2 The String class is part of the java.lang package. Classes in the java.lang package are available by default.
    • 1.15.A.3 A String object is immutable, meaning once a String object is created, its attributes cannot be changed. Methods called on a String object do not change the content of the String object.
    • 1.15.A.4 Two String objects can be concatenated together or combined using the + or += operator, resulting in a new String object. A primitive value can be concatenated with a String object. This causes the implicit conversion of the primitive value to a String object.
    • 1.15.A.5 A String object can be concatenated with any object, which implicitly calls the object's toString method (a behavior that is guaranteed to exist by the inheritance relationship every class has with the Object class). An object's toString method returns a string value representing the object. Subclasses of Object often override the toString method with class-specific implementation. Method overriding occurs when a public method in a subclass has the same method signature as a public method in the superclass, but the behavior of the method is specific to the subclass.
      • Exclusion statement: Overriding the toString method of a class is outside the scope of the AP Computer Science A course and exam.

    1.15.B
    Develop code to call methods on string objects and determine the result of calling these methods.

    • 1.15.B.1 A String object has index values from 0 to one less than the length of the string. Attempting to access indices outside this range will result in a StringIndexOutOfBoundsException.
    • 1.15.B.2 The following String methods—including what they do and when they are used—are part of the Java Quick Reference:
      • int length() returns the number of characters in a String object.
      • String substring(int from, int to) returns the substring beginning at index from and ending at index to - 1.
      • String substring(int from) returns substring(from, length()).
      • int indexOf(String str) returns the index of the first occurrence of str; returns -1 if not found.
      • boolean equals(Object other) returns true if this corresponds to the same sequence of characters as other; returns false otherwise.
      • int compareTo(String other) returns a value < 0 if this is less than other; returns zero if this is equal to other; returns a value > 0 if this is greater than other. Strings are ordered based upon the alphabet.
      • Exclusion statement: Using the equals method to compare one String object with an object of a type other than String is outside the scope of the AP Computer Science A course and exam.
    • 1.15.B.3 A string identical to the single element substring at position index can be created by calling substring(index, index + 1).

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Strings are immutable

    String objects are immutable 不可变 – methods return a new string rather than changing the original. Key methods (all indices start at 0):

    s.length();            // number of characters
    s.substring(2, 5);     // chars at index 2,3,4 (5 excluded)
    s.indexOf("ab");       // first position, or -1
    s.equals(other);       // content comparison (never use == for Strings)
    s.compareTo(other);    // <0, 0, >0 by dictionary order
    

    Exam skill: substring(a, b) includes index a but excludes b, and String comparison must use .equals, not == – two of the most-tested String pitfalls.

    Worked example. Let String s = "COMPUTER"; (indices 0–7). Then s.length() is 8; s.substring(0, 4) is "COMP" (indices 0,1,2,3 – index 4 excluded); s.substring(4) is "UTER" (from index 4 to the end); s.indexOf("PU") is 3; and s.indexOf("X") is -1 (not found). Counting the excluded endpoint of substring is the single most common slip.

    Asking for an index outside 0 to length()-1 (a bad substring or charAt argument, e.g. s.substring(0, 20) here) crashes with a StringIndexOutOfBoundsException – the String cousin of the array-index error.

    String indices start at 0
    String indices start at 0
    Explore · ⁨חקור⁩

    Explore string indices and slicing · ⁨חקרו אינדקסים ומישור של מחרוזות⁩

    Every character has an index, and the numbering starts at 0. Drag the start and end to see how substring(from, to) takes the characters from from up to — but not including — to. · ⁨לכל תווית יש אינדקס, והמינוי מתחיל מ-0. גררו את ההתחלה והסוף כדי לראות כיצד substring(from, to) לוקח את התוויות מfrom ועד (אולם לא כולל) to.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    immutable/ɪˈmjuːtəbl/ בלתי משתנה
    1.15

    Exam tips

    • Trace code by hand line by line, tracking each variable's value in a table — the exam rewards careful tracing over guessing.
    • Know Java's primitive types and that integer division truncates ($7/2$ gives $3$); use a cast or a double for real division.
    • Distinguish compile-time errors (syntax, types) from run-time errors – know the named ones: ArithmeticException (int ÷ 0), NullPointerException (method on a null reference), StringIndexOutOfBoundsException / ArrayIndexOutOfBoundsException – and logic errors (wrong output).
    • Follow operator precedence and initialise every variable before you use it.
    • On the free-response, write complete, compilable Java — return the right type and match the method header exactly.
  • 2

    Selection and Iteration · ⁨בחירה וסיבובים⁩

    Watch lesson · ⁨צפה בשיעור⁩
    2.1

    Selection and Repetition in Algorithms

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.1.A: Represent patterns and algorithms that involve selection and repetition found in everyday life using written language or diagrams.

    • 2.1.A.1 The building blocks of algorithms include sequencing, selection, and repetition.
    • 2.1.A.2 Algorithms can contain selection, through decision making, and repetition, via looping.
    • 2.1.A.3 Selection occurs when a choice of how the execution of an algorithm will proceed is based on a true or false decision.
    • 2.1.A.4 Repetition is when a process repeats itself until a desired outcome is reached.
    • 2.1.A.5 The order in which sequencing, selection, and repetition are used contributes to the outcome of the algorithm.
    עברית

    מטרות למידה 2.1.A: ייצוג דפוסים ואלגוריתמים המכילים בחירה וחזרה הנמצאים בחיי היומיום באמצעות כתיבה או דיאגרמות.

    • 2.1.A.1 בלוקי הבניין של אלגוריתמים כוללים סדריות, בחירה וחזרה.
    • 2.1.A.2 אלגוריתמים יכולים להכיל בחירה, דרך קבלת החלטות, וחזרה, באמצעות לולאות.
    • 2.1.A.3 בחירה מתרחשת כאשר בחירת הכיוון בו תמשיך ביצוע האלגוריתם מבוססת על החלטה נכונה או שגויה.
    • 2.1.A.4 חזרה היא מצב שבו תהליך חוזר על עצמו עד להשגת התוצאה הרצויה.
    • 2.1.A.5 הסדר שבו משתמשים בסדריות, בחירה וחזרה תורם לתוצאת האלגוריתם.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    A flowchart with a decision diamond: selection chooses which path the algorithm takes
    A flowchart with a decision diamond: selection chooses which path the algorithm takes

    Algorithms are built from three control structures 控制结构: sequence (steps in order), selection 选择 (choosing a path), and iteration 迭代 (repeating steps). This topic covers selection and iteration – the tools that let a program make decisions and loop.

    The three control structures: sequence, selection, and iteration
    The three control structures: sequence, selection, and iteration
    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    control structures/kənˈtrəʊl ˈstrʌktʃəz/ מבני בקרה
    selection/sɪˈlekʃn/ בחירה
    iteration/ˌɪtəˈreɪʃn/ איטרציה
    2.2

    Boolean Expressions

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.2.A: Develop code to create Boolean expressions with relational operators and determine the result of these expressions.

    • 2.2.A.1 Values can be compared using the relational operators == and != to determine whether the values are the same. With primitive types, this compares the actual primitive values. With reference types, this compares the object references.
    • 2.2.A.2 Numeric values can be compared using the relational operators <, >, <=, and >= to determine the relationship between the values.
    • 2.2.A.3 An expression involving relational operators evaluates to a Boolean value.
    עברית

    מטרת הלמידה 2.2.A: פיתוח קוד ליצירת ביטויים בוליאניים עם אופרטורים יחסיים והחלטת תוצאת הביטויים האלו.

    • 2.2.A.1 ערכים ניתן להשוות באמצעות אופרטורים יחסים == ו-!= כדי לקבוע האם הערכים זהים. עבור סוגים פרמיטיביים, השוואה זו מבצעת השוואה בין הערכים הפרמיטיביים עצמם. עבור סוגי ייחוס (Reference Types), ההשוואה היא בין הייחוסים של האובייקטים.
    • 2.2.A.2 ערכים מספריים ניתן להשוות באמצעות האופרטורים היחסיים <, >, <= ו->= כדי לקבוע את הקשר בין הערכים.
    • 2.2.A.3 ביטוי המכיל אופרטורים יחסים מתערך לתוצאה בוליאנית.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Logic gates & the half-adder

    A boolean expression 布尔表达式 evaluates to true or false, using relational operators 关系运算符: == (equal), != (not equal), <, >, <=, >=. Note == compares primitive values but object references for objects, so use .equals for Strings.

    The three families of operators: arithmetic, relational, and logical
    The three families of operators: arithmetic, relational, and logical
    Explore · ⁨חקור⁩

    Explore the AND truth table · ⁨חקרו טבלת אמת AND⁩

    A Boolean expression evaluates to true or false. AND is true only when both operands are true; toggle the inputs to see all four cases. · ⁨ביטוי בוליאני מעריך לתוצאת true או false. AND נכון רק כאשר שניהם המקדמים נכונים; הופעים את הקלטות כדי לראות את ארבע המקרים.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    boolean expression/ˈbuːlɪən ekˈspreʃn/ ביטוי בוליאני
    relational operators/rɪˈleɪʃənl ˈɒpəreɪtəz/ אופרטורים יחסים
    2.3

    The if Statement

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.3.A: Develop code to represent branching logical processes by using selection statements and determine the result of these processes.

    • 2.3.A.1 Selection statements change the sequential execution of statements.
    • 2.3.A.2 An if statement is a type of selection statement that affects the flow of control by executing different segments of code based on the value of a Boolean expression.
    • 2.3.A.3 A one-way selection (if statement) is used when there is a segment of code to execute under a certain condition. In this case, the body is executed only when the Boolean expression is true.
    • 2.3.A.4 A two-way selection (if-else statement) is used when there are two segments of code—one to be executed when the Boolean expression is true and another segment for when the Boolean expression is false. In this case, the body of the if is executed when the Boolean expression is true, and the body of the else is executed when the Boolean expression is false.
    עברית

    מטרת הלמידה 2.3.A: פיתוח קוד לייצוג תהליכים לוגיים ענפים באמצעות הוראות בחירה והחלטת תוצאת תהליכים אלו.

    • 2.3.A.1 הוראות בחירה משנות את ביצוע ההוראות ברצף.
    • 2.3.A.2 הוראת if היא סוג של הוראת בחירה המשפיעה על זרימת הבקרה על ידי ביצוע חלקי קוד שונים בהתבסס על ערך הביטוי הبولיאני.
    • 2.3.A.3 בחירה חד-כיוונית (הוראת if) משמשת כאשר יש חלק קוד לביצוע בתנאי מסוים. במקרה זה, הגוף יופעל רק כאשר הביטוי הبولיאני הוא true.
    • 2.3.A.4 בחירה דו-כיוונית (הוראת if-else) משמשת כאשר ישנם שני חלקי קוד – אחד לביצוע כאשר הביטוי הبولיאני הוא true ואחד נוסף לביצוע כאשר הביטוי הبولיאני הוא false. במקרה זה, גוף ה-if יופעל כאשר הביטוי הبولיאני הוא true, וגוף ה-else יופעל כאשר הביטוי הبولיאני הוא false.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    An if statement 条件语句 runs a block only when its condition is true; an optional else gives an alternative:

    if (score >= 60) {
        System.out.println("Pass");
    } else {
        System.out.println("Fail");
    }
    
    Traffic lights: selection chooses which branch runs, just as if statements choose code paths
    Traffic lights: selection chooses which branch runs, just as if statements choose code paths
    Explore · ⁨חקור⁩

    See which branch an if chooses · ⁨ראו איזה ענף if בוחר⁩

    An if statement runs its body only when the condition is true, otherwise it skips to else. Slide the score across the boundaries and watch the grade change. · ⁨הצהרת if מنفذת את הגוף שלה רק כאשר התנאי נכון, אחרת היא דורשת לelse. החליקו את הציון על פני הגבולות וצפו כיצד הציון משתנה.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    if statement/ɪf ˈsteɪtmənt/ הבעת if
    2.4

    Nested if Statements

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.4.A: Develop code to represent nested branching logical processes and determine the result of these processes.

    • 2.4.A.1 Nested if statements consist of if, if-else, or if-else-if statements within if, if-else, or if-else-if statements.
    • 2.4.A.2 The Boolean expression of the inner nested if statement is evaluated only if the Boolean expression of the outer if statement evaluates to true.
    • 2.4.A.3 A multiway selection (if-else-if) is used when there are a series of expressions with different segments of code for each condition. Multiway selection is performed such that no more than one segment of code is executed based on the first expression that evaluates to true. If no expression evaluates to true and there is a trailing else statement, then the body of the else is executed.
    עברית

    מטרת הלמידה 2.4.A: פיתוח קוד לייצוג תהליכים לוגיים ענפים מקוננים והחלטת תוצאת תהליכים אלו.

    • 2.4.A.1 הוראות if מקוננות מכילות בתוכם הוראות if, if-else או if-else-if בתוך הוראות if, if-else או if-else-if.
    • 2.4.A.2 הביטוי הبولיאני של ה-if המקוננת הפנימית מתערך רק אם הביטוי הبولיאני של ה-if החיצוני מתערך לתוצאה true.
    • 2.4.A.3 בחירה רב-דרכית (if-else-if) משמשת כאשר יש סדרה של ביטויים עם חלקי קוד שונים לכל תנאי. בחירה רב-דרכית מתבצעת כך שאין יותר מחלקת קוד אחת שתופעל, בהתבסס על הביטוי הראשון שמעריך לתוצאת true. אם אין ביטוי שמעריך לתוצאת true ויש statement else בסוף, אז גוף ה-else יופעל.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Placing an if inside another, or chaining with else if, tests several cases in order. Only the first matching branch runs:

    if (g >= 90) grade = 'A';
    else if (g >= 80) grade = 'B';
    else grade = 'C';
    
    2.5

    Compound Boolean Expressions

    Syllabus · ⁨סיילבוס⁩
    Learning ObjectiveEssential Knowledge

    2.5.A
    Develop code to represent compound Boolean expressions and determine the result of these expressions.

    • 2.5.A.1 Logical operators ! (not), && (and), and || (or) are used with Boolean expressions. The expression !a evaluates to true if a is false and evaluates to false otherwise. The expression a && b evaluates to true if both a and b are true and evaluates to false otherwise. The expression a || b evaluates to true if a is true, b is true, or both, and evaluates to false otherwise. The order of precedence for evaluating logical operators is ! (not), && (and), then || (or). An expression involving logical operators evaluates to a Boolean value.
    • 2.5.A.2 Short-circuit evaluation occurs when the result of a logical operation using && or || can be determined by evaluating only the first Boolean expression. In this case, the second Boolean expression is not evaluated.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Short-circuit evaluation

    Logical operators 逻辑运算符 combine conditions: && (and – both true), || (or – at least one true), ! (not – reverse). Java uses short-circuit evaluation 短路求值: && stops if the left side is false, and || stops if the left side is true – useful to guard against errors, e.g. if (n != 0 && total / n > 5).

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Logical operators/ˈlɒdʒɪkl ˈɒpəreɪtəz/ מפעילים לוגיים
    short-circuit evaluation/ʃɔːt ˈsɜːkɪt ɪˌvæljuːˈeɪʃn/ הערכת קיצור מסלול
    2.6

    Comparing Boolean Expressions

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.6.A: Compare equivalent Boolean expressions.

    • 2.6.A.1 Two Boolean expressions are equivalent if they evaluate to the same value in all cases. Truth tables can be used to prove Boolean expressions are equivalent.
    • 2.6.A.2 De Morgan's law can be applied to Boolean expressions to create equivalent Boolean expressions. Under De Morgan's law, the Boolean expression !(a && b) is equivalent to !a || !b and the Boolean expression !(a || b) is equivalent to !a && !b.

    Learning Objective 2.6.B: Develop code to compare object references using Boolean expressions and determine the result of these expressions.

    • 2.6.B.1 Two different variables can hold references to the same object. Object references can be compared using == and !=.
    • 2.6.B.2 An object reference can be compared with null, using == or !=, to determine if the reference actually references an object.
    • 2.6.B.3 Classes often define their own equals method, which can be used to specify the criteria for equivalency for two objects of the class. The equivalency of two objects is most often determined using attributes from the two objects.
      • Exclusion statement: Overriding the equals method is outside the scope of the AP Computer Science A course and exam.
    עברית

    מטרת למידה 2.6.A: השוו בין ביטויים בוליאניים שוויונים.

    • 2.6.A.1 שני ביטויים בוליאניים הם שוויונים אם הם מעריכים לערך זהה בכל המקרים. טבלאות אמת יכולות לשמש להוכחת שוויון ביטויים בוליאניים.
    • 2.6.A.2 ניתן להחיל את חוק דה מורגן על ביטויים בוליאניים כדי ליצור ביטויים בוליאניים שוויונים. לפי חוק דה מורגן, הביטוי הבוליאני !(a && b) הוא שווה ל!a || !b והביטוי הבוליאני !(a || b) הוא שווה ל!a && !b.

    מטרת למידה 2.6.B: פתח קוד להשוואת רפרנסים לאובייקטים באמצעות ביטויים בוליאניים וקבע את התוצאה של ביטויים אלו.

    • 2.6.B.1 שני משתנים שונים יכולים להכיל רפרנסים לאותו אובייקט. רפרנסים לאובייקטים ניתנים להשוואה באמצעות == ו!=.
    • 2.6.B.2 רפרנס לאובייקט יכול להיות מושווה לnull, באמצעות == או !=, כדי לקבוע האם הרפרנס מתייחס באמת לאובייקט.
    • 2.6.B.3 מחלקות מגדירות לעיתים קרובות את שיטת equals שלהן, שהיא יכולה לשמש לציין הקריטריונים לשוויון בין שני אובייקטים מהמחלקה. השוויון בין שני אובייקטים נקבע ברוב המקרים באמצעות מאפיינים משני האובייקטים.
      • הצהרת בלעדיות: החלפת שיטת equals היא מחוץ לתחום הלימודים בקורס ובמבחן AP Computer Science A.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    De Morgan's laws 德摩根定律 rewrite negations: !(a && b) equals !a || !b, and !(a || b) equals !a && !b. Two boolean expressions are equivalent if they give the same result for every input – a truth table proves it. Simplifying conditions this way is a common exam task.

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    De Morgan's laws/də ˈmɔːɡənz lɔːz/ חוקי דה מורגן
    2.7

    while Loops

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.7.A: Identify when an iterative process is required to achieve a desired result.

    • 2.7.A.1 Iteration is a form of repetition. Iteration statements change the flow of control by repeating a segment of code zero or more times as long as the Boolean expression controlling the loop evaluates to true.
    • 2.7.A.2 An infinite loop occurs when the Boolean expression in an iterative statement always evaluates to true.
    • 2.7.A.3 The loop body of an iterative statement will not execute if the Boolean expression initially evaluates to false.
    • 2.7.A.4 Off by one errors occur when the iteration statement loops one time too many or one time too few.

    Learning Objective 2.7.B: Develop code to represent iterative processes using while loops and determine the result of these processes.

    • 2.7.B.1 A while loop is a type of iterative statement. In while loops, the Boolean expression is evaluated before each iteration of the loop body, including the first. When the expression evaluates to true, the loop body is executed. This continues until the Boolean expression evaluates to false, whereupon the iteration terminates.
    עברית

    מטרת למידה 2.7.A: זיהוי מתי נדרש תהליך איטרטיבי (איטרציה) כדי להשיג תוצאה רצויה.

    • 2.7.A.1 איטרציה היא סוג של חזרה. פקודות איטרציה משנות את זרימת הבקרה על ידי חזרה על קטע קוד מספר אפס או יותר כל עוד הביטוי הבוליאני השולט בלולאה מעריך לtrue.
    • 2.7.A.2 לולאת אינסוף מתרחשת כאשר הביטוי הבוליאני בפקודת איטרציה מעריך תמיד לtrue.
    • 2.7.A.3 גוף הלולאה של פקודת איטרציה לא יופעל אם הביטוי הבוליאני מעריך בהתחלה לfalse.
    • 2.7.A.4 טעאות Off by one מתרחשות כאשר פקודת האיטרציה לולאת פעם אחת יותר מדי או פעם אחת פחות מדי.

    מטרת למידה 2.7.B: פתח קוד לייצוג תהליכים איטרטיביים באמצעות לולאות while וקבע את תוצאת תהליכים אלו.

    • 2.7.B.1 לולאת while היא סוג של פקודת איטרציה. בלולאות while, הביטוי הבוליאני מעריך לפני כל איטרציה בגוף הלולאה, כולל הראשונה. כאשר הביטוי מעריך לtrue, גוף הלולאה מופעל. הדבר נמשך עד שהביטוי הבוליאני מעריך לfalse, עתה האיטרציה מסתיימת.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    A while loop 循环 repeats while its condition stays true, testing before each pass. You must change something inside so the loop eventually stops, or it becomes an infinite loop 无限循环:

    The three loop types differ in where the condition is tested
    The three loop types differ in where the condition is tested
    int i = 0;
    while (i < 5) {
        System.out.println(i);
        i++;
    }
    
    Explore · ⁨חקור⁩

    Trace a while loop · ⁨עקוב אחר לולאת while⁩

    A while loop repeats as long as its condition stays true, updating its variables each pass. Step through to see the sum of squares build up. · ⁨לולאת while חוזרת כל עוד התנאי שלה נשאר אמת, ומעדכנת את המשתנים בכל מעבר. צעדו כדי לראות כיצד סכום הריבועים עולה.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    while loop/waɪl luːp/ לולאת while
    infinite loop/ˈɪnfɪnət luːp/ לולאת אינסוף
    2.8

    for Loops

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.8.A: Develop code to represent iterative processes using for loops and determine the result of these processes.

    • 2.8.A.1 A for loop is a type of iterative statement. There are three parts in a for loop header: the initialization, the Boolean expression, and the update.
    • 2.8.A.2 In a for loop, the initialization statement is only executed once before the first Boolean expression evaluation. The variable being initialized is referred to as a loop control variable. The Boolean expression is evaluated immediately after the loop control variable is initialized and then following each execution of the increment statement until it is false. In each iteration, the update is executed after the entire loop body is executed and before the Boolean expression is evaluated again.
    • 2.8.A.3 A for loop can be rewritten into an equivalent while loop (and vice versa).
    עברית

    מטרת למידה 2.8.A: פתח קוד לייצוג תהליכים איטרטיביים באמצעות לולאות for וקבע את תוצאת תהליכים אלו.

    • 2.8.A.1 לולאת for היא סוג של פקודה איטרטיבית. בראש לולאת for ישנם שלושה חלקים: ההתחלה, הביטוי הבוליאני, והעדכון.
    • 2.8.A.2 בלולאת for, פקודת ההתחלה מופעלת רק פעם אחת לפני הערכת הביטוי הבוליאני הראשונה. המשתנה הנאפס הוא משתנה בקרת הלולאה. הביטוי הבוליאני מוערך מיד לאחר אפסת משתנה בקרת הלולאה ולאחר מכן לאחר כל ביצוע של פקודת ההגברה עד שהוא false. בכל איטרציה, העדכון מתבצע לאחר ביצוע גוף הלולאה כולו ולפני הערכת הביטוי הבוליאני שוב.
    • 2.8.A.3 לולאת for ניתן להפוך ללולאת while שקולה (ולהפך).

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    A for loop packs initialization, condition, and update into one line – best when you know the count:

    for (int i = 0; i < n; i++) {
        // runs n times, i = 0..n-1
    }
    

    A for and an equivalent while do the same work; be able to convert between them.

    An assembly line: loops repeat a process for every item, like for and while
    An assembly line: loops repeat a process for every item, like for and while
    Explore · ⁨חקור⁩

    Trace a for loop · ⁨עקוב אחר לולאת for⁩

    A for loop runs a fixed number of times, its counter stepping through a range. Watch the counter and running total advance one pass at a time. · ⁨לולאת for פועלת מספר קבוע של פעמים, כאשר הספן שלה עובר על טווח. צפו בספן ובסך הנאסף מתקדמים צעד אחד בכל מעבר.⁩

    2.9

    Building Complete Selection and Iteration Algorithms

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.9.A: Develop code for standard and original algorithms (without data structures) and determine the result of these algorithms.

    • 2.9.A.1 There are standard algorithms to:
      • identify if an integer is or is not evenly divisible by another integer
      • identify the individual digits in an integer
      • determine the frequency with which a specific criterion is met
      • determine a minimum or maximum value
      • compute a sum or average
    עברית

    מטרות למידה 2.9.A: פיתוח קוד עבור אלגוריתמים סטנדרטיים וחדשים (ללא מבני נתונים) וקביעת התוצאה של אלגוריתמים אלו.

    • 2.9.A.1 קיימים אלגוריתמים סטנדרטיים ל:
      • זיהוי אם מספר שלם מתחלק או לא מתחלק במספר שלם אחר באופן שווה
      • זיהוי הספרות הבודדות במספר שלם
      • קביעת התדירות בה נמצאים תנאי ספציפי
      • קביעת ערך מינימום או מקסימום
      • חישוב סכום או ממוצע

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Combine loops and conditions to solve real problems – count, sum, find a maximum, or test a property:

    int max = arr[0];
    for (int k = 1; k < arr.length; k++) {
        if (arr[k] > max) max = arr[k];
    }
    

    Two integer patterns the exam tests directly use % and /. To read the digits of an integer one at a time, repeatedly take n % 10 (the last digit) and then n = n / 10 (drop it). To test divisibility, n % d == 0 means n is evenly divisible by d. Combine them with a counter to find the frequency with which some criterion is met.

    Standard patterns like a running total, a counter, or a flag 标志 (a boolean that records whether something happened) recur throughout the course.

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    flag/flæɡ/ דגל
    2.10

    String Algorithms

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.10.A: Develop code for standard and original algorithms that involve strings and determine the result of these algorithms.

    • 2.10.A.1 There are standard string algorithms to:
      • find if one or more substrings have a particular property
      • determine the number of substrings that meet specific criteria
      • create a new string with the characters reversed
    עברית

    מטרות למידה 2.10.A: פיתוח קוד לאלגוריתמים סטנדרטיים וראשוניים המכילים מחרוזות וקביעת תוצאת אלגוריתמים אלו.

    • 2.10.A.1 קיימים אלגוריתמי מחרוזות סטנדרטיים ל:
      • מציאת מחרוזת-בת אחת או יותר בעלות מאפיין מסוים
      • קביעת מספר מחרוזות-בת העומדות בקריטריונים ספציפיים
      • יצירת מחרוזת חדשה עם תווים הפוכים

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Loop through a string by index to process each character:

    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        // count vowels, reverse, check for a substring, ...
    }
    

    Typical tasks: count occurrences, build a reversed or filtered copy, or test whether one string contains another.

    2.11

    Nested Iteration

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.11.A: Develop code to represent nested iterative processes and determine the result of these processes.

    • 2.11.A.1 Nested iteration statements are iteration statements that appear in the body of another iteration statement. When a loop is nested inside another loop, the inner loop must complete all its iterations before the outer loop can continue to its next iteration.
    עברית

    מטרות למידה 2.11.A: פיתוח קוד ליצוג תהליכי איטרציה משובצים וקביעת תוצאת תהליכים אלו.

    • 2.11.A.1 פקודות איטרציה משובצות הן פקודות איטרציה המופיעות בגוף פקודת איטרציה אחרת. כאשר לולאה משובצת בתוך לולאה אחרת, הלולאה הפנימית חייבת להשלים את כל האיטרציות שלה לפני שהלולאה החיצונית תוכל להמשיך לאיטרציה הבאה שלה.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    A nested loop 嵌套循环 puts one loop inside another; the inner loop completes fully for each pass of the outer. If the outer runs $n$ times and the inner $m$ times, the body runs $n\times m$ times – the basis for processing grids and comparing all pairs.

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    nested loop/ˈnestɪd luːp/ לולאה מקושרת
    2.12

    Informal Run-Time Analysis

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 2.12.A: Calculate statement execution counts and informal run-time comparison of iterative statements.

    • 2.12.A.1 A statement execution count indicates the number of times a statement is executed by the program. Statement execution counts are often calculated informally through tracing and analysis of the iterative statements.
    עברית

    מטרות למידה 2.12.A: חישוב ספירות ביצוע פקודות והשוואה אי-פורמלית בזמן ריצה של פקודות איטרציה.

    • 2.12.A.1 מניית ביצועי הוראה מציינת את מספר הפעמים שבהן הוראה מופעלת על ידי התוכנית. לעיתים קרובות נחשב מניית ביצועים באופן לא רשמי באמצעות עקב וניתוח של הוראות איטרטיביות.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    Big-O growth rates

    Run-time analysis 运行时间分析 counts how many basic steps an algorithm takes as the input size $n$ grows. Count the executions of the innermost statement: a single loop over $n$ items is linear ($n$ steps); two nested loops over $n$ are quadratic ($n^2$). This informal counting lets you compare two algorithms' efficiency.

    How the running time grows with the number of elements n
    How the running time grows with the number of elements n

    Exam skill: for a nested loop, be able to state how many times the inner statement runs in terms of the loop bounds – a frequent multiple-choice question.

    Worked example. How many stars does this print?

    for (int i = 0; i < 4; i++)
        for (int j = 0; j < i; j++)
            System.out.print("*");
    

    The inner loop runs i times for each outer i: 0 + 1 + 2 + 3 = 6 stars. When the inner bound is the outer variable, the total is the triangular sum $0+1+\dots+(n-1)=\dfrac{n(n-1)}{2}$ – here $\dfrac{4\times3}{2}=6$ – not the full $n^2=16$ of a rectangular nested loop.

    Explore · ⁨חקור⁩

    Compare how algorithms scale · ⁨השווו כיצד אלגוריתמים גדלים⁩

    Run-time describes how the number of steps grows with the input size $n$. Increase $n$ and watch a linear $O(n)$ pull far ahead of a quadratic $O(n^2)$. · ⁨זמן ביצוע מתאר כיצד מספר הפעולות גדל עם גודל הקלט $n$. הגדילו את $n$ וצפו כיצד אלגוריתם ליניארי $O(n)$ מרחיק מאלגוריתם ריבועי $O(n^2)$.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Run-time analysis/rʌn taɪm əˈnæləsɪs/ ניתוח בזמן הרצה
    2.12

    Exam tips

    • Get boundary conditions right: use < vs <= deliberately, and watch the first and last iteration of every loop (off-by-one is the classic bug).
    • Build compound conditions with &&, ||, ! and remember short-circuit evaluation (put the null check first).
    • Trace nested loops by counting how many times the inner body runs in total.
    • Choose the right structure — if/else if for ranges, a loop for repetition — and avoid an infinite loop by updating the loop variable.
    • Apply De Morgan's laws when you simplify or negate a boolean condition.
  • 3

    Class Creation · ⁨יצירת מחלקות⁩

    Watch lesson · ⁨צפה בשיעור⁩
    3.1

    Abstraction and Program Design · ⁨שכלול ועיצוב תוכנה⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 3.1.A: Represent the design of a program by using natural language or creating diagrams that indicate the classes in the program and the data and procedural abstractions found in each class by including all attributes and behaviors.

    • 3.1.A.1 Abstraction is the process of reducing complexity by focusing on the main idea. By hiding details irrelevant to the question at hand and bringing together related and useful details, abstraction reduces complexity and allows one to focus on the idea.
    • 3.1.A.2 Data abstraction provides a separation between the abstract properties of a data type and the concrete details of its representation. Data abstraction manages complexity by giving data a name without referencing the specific details of the representation. Data can take the form of a single variable or a collection of data, such as in a class or a set of data.
    • 3.1.A.3 An attribute is a type of data abstraction that is defined in a class outside any method or constructor. An instance variable is an attribute whose value is unique to each instance of the class. A class variable is an attribute shared by all instances of the class.
    • 3.1.A.4 Procedural abstraction provides a name for a process and allows a method to be used only knowing what it does, not how it does it. Through method decomposition, a programmer breaks down larger behaviors of the class into smaller behaviors by creating methods to represent each individual smaller behavior. A procedural abstraction may extract shared features to generalize functionality instead of duplicating code. This allows for code reuse, which helps manage complexity.
    • 3.1.A.5 Using parameters allows procedures to be generalized, enabling the procedures to be reused with a range of input values or arguments.
    • 3.1.A.6 Using procedural abstraction in a program allows programmers to change the internals of a method (to make it faster, more efficient, use less storage, etc.) without needing to notify method users of the change as long as the method signature and what the method does is preserved.
    • 3.1.A.7 Prior to implementing a class, it is helpful to take time to design each class including its attributes and behaviors. This design can be represented using natural language or diagrams.
    עברית

    מטרות למידה 3.1.A: ייצוג עיצוב תוכנית באמצעות שפה טבעית או ליצירת דיאגרמות המציינות את הכיתות בתוכנית ואת השתקות הנתונים והשלכות המצויות בכל כיתה על ידיכלול כל האטריביוטים וההתנהגויות.

    • 3.1.A.1 השתקה היא תהליך של הפחתת מורכבות על ידי התמקדות ברעיון המרכזי. על ידי הסתרת פרטים שאינם רלוונטיים לשאלה הקיימת וקיבוצי פרטים קשורים ומفيدים, השתקה מפחיתה מורכבות ומאפשרת להתמקד ברעיון.
    • 3.1.A.2 השתקת נתונים מספקת הפרדה בין התכונות המופשטות של סוג נתונים לבין הפרטים הממשיים של ההצגה שלה. השתקת נתונים מנהלת מורכבות על ידי מתן שם לנתונים ללא הייחוס לפרטים הספציפיים של ההצגה. הנתונים יכולים לקבל צורה של משתנה בודד או אוסף נתונים, כגון בכיתה או בערכת נתונים.
    • 3.1.A.3 אטריביוט הוא סוג של השתקת נתונים המוגדרת בכיתה מחוץ לכל שיטה או בונה. משתנה אובייקט הוא אטריביוט שערכו ייחודי לכל אובייקט של הכיתה. משתנה כיתה הוא אטריביוט המשותף לכל האובייקטים של הכיתה.
    • 3.1.A.4 השתקה של שלבים מספקת שם לתהליך ומאפשרת לשיטה להיות מופעלת רק כאשר יודעים מה היא עושה, לא כיצד היא עושה זאת. באמצעות פירוק שיטות, מתכנת מפרק התנהגויות גדולות יותר של הכיתה להתנהגויות קטנות יותר על ידי יצירת שיטות המייצגות כל התנהגות קטנה בודדת. השתקת שלבים עשויה לחלץ מאפיינים משותפים כדי לגנרלize פונקציונליות במקום להכפיל קוד. זה מאפשר שימוש חוזר בקוד, שמסייע בניהול מורכבות.
    • 3.1.A.5 השימוש בפארמטרים מאפשר גנרלזציה של הליכים, ומאפשר לשימוש חוזר בהם עם מגוון ערכי כניסה או ארגומנטים.
    • 3.1.A.6 השימוש בהשתקת שלבים בתוכנית מאפשר למתכנתים לשנות את הפנים של שיטה (כדי להפכה מהירה יותר, יעילה יותר, לצרוך פחות אחסון, וכו') ללא הצורך בהודעת משתמשי השיטה על השינוי כל עוד חתימת השיטה ומה שהשיטה עושה נשמרים.
    • 3.1.A.7 לפני מימוש כיתה, מומלץ לקחת זמן לעצב כל כיתה כולל את האטריביוטים וההתנהגויות שלה. עיצוב זה ניתן לייצוג באמצעות שפה טבעית או דיאגרמות.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    Abstraction 抽象 means hiding detail behind a simple interface – you use a String without knowing how it stores characters. Good design breaks a problem into classes, each responsible for one idea. This topic is about writing your own classes.

    עברית
    פאזל בתהליך: מחלקות ומתודות הן חלקים מודולריים לעיצוב תוכנה גדול יותר
    פאזל בתהליך: מחלקות ומתודות הן חלקים מודולריים לעיצוב תוכנה גדול יותר

    שכלול אומר להסתיר פרטים מאחורי ממשק פשוט – אתם משתמשים ב-String מבלי לדעת כיצד הוא מאחסן תוויות. עיצוב טוב מפצל בעיה למחלקות, שכל אחת אחראית על רעיון אחד. נושא זה עוסק בכתיבת המחלקות שלך.

    פירוק תוכנה למודולים ותת-מודולים
    פירוק תוכנית למודולים ותת-מודולים
    3.2

    The Impact of Program Design · ⁨השפעת עיצוב התוכנה⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 3.2.A: Explain the social and ethical implications of computing systems.

    • 3.2.A.1 System reliability refers to the program being able to perform its tasks as expected under stated conditions without failure. Programmers should make an effort to maximize system reliability by testing the program with a variety of conditions.
    • 3.2.A.2 The creation of programs has impacts on society, the economy, and culture. These impacts can be both beneficial and harmful. Programs meant to fill a need or solve a problem can have unintended harmful effects beyond their intended use.
    • 3.2.A.3 Legal issues and intellectual property concerns arise when creating programs. Programmers often reuse code written by others and published as open source and free to use. Incorporation of code that is not published as open source requires the programmer to obtain permission and often purchase the code before integrating it into their program.
    עברית

    מטרות למידה 3.2.A: הסבר על ההשלכות החברתיות והאתיות של מערכות מחשוב.

    • 3.2.A.1 אמינות מערכת מתייחסת ליכולת התוכנית לבצע את משימותיה כפי שצפוי בתנאים המפורשים ללא כישלון. מתכנתים צריכים להשקיע מאמץ במקסום אמינות המערכת על ידי בדיקת התוכנית עם מגוון תנאים שונים.
    • 3.2.A.2 יצירת תוכניות משפיעה על החברה, הכלכלה והתרבות. השפעות אלו יכולות להיות גם חיוביות וגם שליליות. תוכניות שמיועדות למלא צורך או לפתור בעיה עשויות לגרום להשלכות מזיקות לא רצויות מעבר לשימוש הנכון שלהן.
    • 3.2.A.3 נושאים משפטיים ודאגות בנוגע לזכויות יוצרים ועליון אינטלקטואלי נובעים במהלך יצירת תוכניות. מתכנתים לעיתים קרובות משתמשים מחדש בקוד שנכתב על ידי אחרים ופורסם כקוד פתוח ומחופשי לשימוש. שימוש בקוד שאינו פורסם כקוד פתוח דורש מהמתכנת לקבל רשות ולעיתים קרובות גם לרכוש את הקוד לפני שמשלב אותו בתוכנית שלו.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    Design choices affect whether code is correct, readable, and reusable. Encapsulation 封装 – keeping data private and exposing it only through methods – protects an object's state from misuse and lets you change the inside without breaking users of the class. Thoughtful naming, single-purpose methods, and testing reduce bugs.

    Design also carries responsibility beyond the code. System reliability 系统可靠性 - a program performing its tasks as expected, without failure - is something programmers should maximise through careful design and testing. Programs have real impacts on society, the economy, and culture that can be both beneficial and harmful. And creating programs raises legal and intellectual-property 知识产权 concerns: programmers often reuse code published as open source 开源 and free to use, but must respect its licence and give credit rather than copy others' work as their own.

    עברית

    בחירות עיצוב משפיעות על כך שהקוד יהיה נכון, קריא ושימוש-מחדש. אקספולציה – שמירת נתונים כפרטיים וחשיפתם רק דרך מתודות – מגנה על מצב האובייקט משימוש לא תקין ומאפשרת לשנות את הפנים מבלי לפגוע במשתמשי המחלקה. סימון מחושב, מתודות בעלות מטרה אחת ובדיקות מקטינים באגים.

    העיצוב כולל גם אחריות מעבר לקוד. אמינות מערכת - ביצוע תוכנית למשימותיה בצורה הצפויה, ללא כשל - הוא משהו שתוכנתנים צריכים למקסם דרך עיצוב ובדיקה קפדניים. לתוכניות יש השפעות אמיתיות על החברה, הכלכלה והתרבות שיכולות להיות גם מועילות וגם מזיקות. ויצירת תוכניות מעלה דאגות משפטיות ורכושיות: תוכנתנים לעיתים קרובות משתמשים מחדש בקוד שפורסם כ-code פתוח וזמין בחינם, אך עליהם לכבד את הרישיון שלו ולהעריך זכות במקום להעתיק עבודת אחרים כשלהם.

    3.3

    The Anatomy of a Class · ⁨אנטומיה של מחלקה⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 3.3.A: Develop code to designate access and visibility constraints to classes, data, constructors, and methods.

    • 3.3.A.1 Data encapsulation is a technique in which the implementation details of a class are kept hidden from external classes. The keywords public and private affect the access of classes, data, constructors, and methods. The keyword private restricts access to the declaring class, while the keyword public allows access from classes outside the declaring class.
    • 3.3.A.2 In this course, classes are always designated public and are declared with the keyword class.
    • 3.3.A.3 In this course, constructors are always designated public.
    • 3.3.A.4 Instance variables belong to the object, and each object has its own copy of the variable.
    • 3.3.A.5 Access to attributes should be kept internal to the class in order to accomplish encapsulation. Therefore, it is good programming practice to designate the instance variables for these attributes as private unless the class specification states otherwise.
    • 3.3.A.6 Access to behaviors can be internal or external to the class. Methods designated as public can be accessed internally or externally to a class, whereas methods designated as private can only be accessed internally to the class.
    עברית

    מטרות למידה 3.3.A: פיתוח קוד כדי לקבוע מגבלות גישה ונראות עבור מחלקות, נתונים, בוני-בנייה (constructors) ומתודות.

    • 3.3.A.1 עיטוף נתונים היא טכניקה בה פרטי היישום של מחלקה נשמרים בסתר ממחלקות חיצוניות. המילים public וprivate משפיעות על הגישה למחלקות, נתונים, בוני-בנייה ומתודות. המילה private מגבילה גישה למחלקה המצהירה בלבד, בעוד שהמילה public מאפשרת גישה ממחלקות מחוץ למחלקה המצהרת.
    • 3.3.A.2 בקורס זה, מחלקות מסומנות תמיד כpublic ומוגדרות עם המילה class.
    • 3.3.A.3 בקורס זה, בוני-בנייה מסומנים תמיד כpublic.
    • 3.3.A.4 משתנים ממוחלקים (Instance variables) שייכים לאובייקט, ולכל אובייקט יש העתק משלו של המשתנה.
    • 3.3.A.5 גישה לתכונות (attributes) צריכה להיות מוגבלת בפנים המחלקה כדי להשגת עיטוף. לכן, זוהי שיטה תכנותית טובה לסמן את המשתנים הממוחלקים עבור תכונות אלו כprivate אלא אם כן שיתוף הפעולה של המחלקה קובע אחרת.
    • 3.3.A.6 גישה להתנהגויות יכולה להיות פנימית או חיצונית למחלקה. מתודות המסומנות כpublic ניתנות לגישה פנימית או חיצונית למחלקה, בעוד שמתודות המסומנות כprivate ניתנות לגישה רק בפנים המחלקה.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    A class has three parts: instance variables 实例变量 (fields – the object's data), constructors (build objects), and methods (behavior). Fields are usually private; methods are usually public:

    עברית

    למחלקה יש שלושה חלקים: משתני instance (שדות – הנתונים של האובייקט), constructors (בונים אובייקטים) ו-מתודות (התנהגות). שדות הם בדרך כלל private; מתודות הן בדרך כלל public:

    תרשים מחלקה: מאפיינים פרטיים ושיטות ציבוריות
    תרשים מחלקה: מאפיינים פרטיים ושיטות ציבוריות
    public class Student {
        private String name;      // instance variable
        private int score;
    
        public Student(String n, int s) {   // constructor
            name = n;
            score = s;
        }
        public int getScore() { return score; }   // accessor
    }
    
    תוכנית: מחלקה היא תבנית המגדירה כיצד אובייקטים מסוג זה נבנים
    תוכנית: מחלקה היא תבנית המגדירה כיצד אובייקטים מסוג זה נבנים
    Explore · ⁨חקור⁩

    See an object's fields as boxes · ⁨ראו שדות של אובייקת כתיבות⁩

    A class groups related data (its fields) and methods. Each object gets its own set of field boxes; assigning to one changes that object only. · ⁨מחלקה מקבוצה נתונים קשורים (ה-שדות שלה) ומתודות. לכל אובייקת יש סט תיבות שדות משלו; שינוי בשדה של אחד משנה רק את האובייקת ההוא.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Abstraction/əbˈstrækʃn/ אבסטרקציה
    Encapsulation/ɪnˌkæpsjʊˈleɪʃn/ עטיפה
    System reliability/ˈsɪstəm rɪˌlaɪəˈbɪlɪti/ אמינות מערכת
    legal and intellectual-property/ˈliːɡl ænd ˌɪntəˈlektʃuːəl ˈprɒpəti/ זכויות משפטיות ונכסי קניין רוחני
    open source/ˈəʊpən sɔːs/ קוד פתוח
    instance variables/ˈɪnstəns ˈveərɪəblz/ משתני אקספלן (Instance variables)
    constructor/kənˈstrʌktə/ בונה
    accessor (getter)/əkˈsesə/ שליף (getter)
    3.4

    Constructors

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 3.4.A: Develop code to declare instance variables for the attributes to be initialized in the body of the constructors of a class.

    • 3.4.A.1 An object's state refers to its attributes and their values at a given time and is defined by instance variables belonging to the object. This defines a has-a relationship between the object and its instance variables.
    • 3.4.A.2 A constructor is used to set the initial state of an object, which should include initial values for all instance variables. When a constructor is called, memory is allocated for the object and the associated object reference is returned. Constructor parameters, if specified, provide data to initialize instance variables.
    • 3.4.A.3 When a mutable object is a constructor parameter, the instance variable should be initialized with a copy of the referenced object. In this way, the instance variable does not hold a reference to the original object, and methods are prevented from modifying the state of the original object.
    • 3.4.A.4 When no constructor is written, Java provides a no-parameter constructor, and the instance variables are set to default values according to the data type of the attribute. This constructor is called the default constructor.
    • 3.4.A.5 The default value for an attribute of type int is 0. The default value of an attribute of type double is 0.0. The default value of an attribute of type boolean is false. The default value of a reference type is null.
    עברית

    מטרות למידה 3.4.A: פיתוח קוד כדי להצהיר משתנים ממוחלקים עבור התכונות שיועדים להתחיל בשיקוף בוני-הבנייה של מחלקה.

    • 3.4.A.1 מצב (state) של אובייקט מתייחס לתכונותיו וערכיהן בזמן נתון, והוא מוגדר על ידי משתנים ממוחלקים השייכים לאובייקט. הדבר מגדיר יחס "יש-א-" (has-a) בין האובייקט לבין המשתנים הממוחלקים שלו.
    • 3.4.A.2 בונה-בנייה משמש להגדרת המצב ההתחלתי של אובייקט, הכולל ערכים התחלתיים לכל המשתנים הממוחלקים. כאשר בונה-בנייה נקרא, זיכרון מוקצה עבור האובייקט והערות האובייקט הקשורה מוחזרת. פרמטרי בונה-הבנייה, אם מצוינים, מספקים נתונים להתחלת משתנים ממוחלקים.
    • 3.4.A.3 כאשר אובייקט משתנה (mutable object) הוא פרמטר בונה-בנייה, המשתנה הממוחלק צריך להתחיל בהעתק של האובייקט המצויין. באופן זה, המשתנה הממוחלק אינו מחזיק ברפרנס לאובייקט המקורי, ומתודות מונעות משינוי המצב של האובייקט המקורי.
    • 3.4.A.4 כאשר אין כתוב בונה-בנייה, Java מספקת בונה-בנייה ללא פרמטרים, והמשתנים הממוחלקים מוגדרים לערכים ברירת מחדל בהתאם לסוג הנתונים של התכונה. בונה זה מכונה בונה-בנייה ברירת מחדל.
    • 3.4.A.5 הערך הרירת מחדל לתכונה מסוג int הוא 0. הערך ברירת מחדל לתכונה מסוג double הוא 0.0. הערך ברירת מחדל לתכונה מסוג boolean הוא false. הערך ברירת מחדל לסוג עיטוף (reference type) הוא null.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    A constructor 构造函数 has the same name as the class and no return type. It runs when you write new, and its job is to initialize the fields. A class can have several constructors with different parameter lists (overloading 重载); a no-argument constructor sets defaults.

    עברית

    Constructor יש לו אותו שם כמו המחלקה ואין לו סוג החזרה. הוא רץ כאשר אתם כותבים new, ומשימתו היא לאיפוס השדות. למחלקה יכול להיות מספר several constructors עם רשימות פרמטרים שונות (overloading); constructor ללא פרמטרים קובע ברירת מחדל.

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    overloading/ˌəʊvəˈləʊdɪŋ/ עמיסה (Overloading)
    3.5

    Methods: How to Write Them · ⁨שיטות: כיצד לכתוב אותן⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 3.5.A: Develop code to define behaviors of an object through methods written in a class using primitive values and determine the result of calling these methods.

    • 3.5.A.1 A void method does not return a value. Its header contains the keyword void before the method name.
    • 3.5.A.2 A non-void method returns a single value. Its header includes the return type in place of the keyword void.
    • 3.5.A.3 In non-void methods, a return expression compatible with the return type is evaluated, and the value is returned. This is referred to as return by value.
    • 3.5.A.4 The return keyword is used to return the flow of control to the point where the method or constructor was called. Any code that is sequentially after a return statement will never be executed. Executing a return statement inside a selection or iteration statement will halt the statement and exit the method or constructor.
    • 3.5.A.5 An accessor method allows objects of other classes to obtain a copy of the value of instance variables or class variables. An accessor method is a non-void method.
    • 3.5.A.6 A mutator (modifier) method is a method that changes the values of the instance variables or class variables. A mutator method is often a void method.
    • 3.5.A.7 Methods with parameters receive values through those parameters and use those values in accomplishing the method's task.
    • 3.5.A.8 When an argument is a primitive value, the parameter is initialized with a copy of that value. Changes to the parameter have no effect on the corresponding argument.
    עברית

    מטרות למידה 3.5.A: פיתוח קוד להגדרת התנהגויות של אובייקט באמצעות שיטות שנכתבו בכיתה, תוך שימוש בערכים ראשוניים, וקביעת התוצאה של קריאת שיטות אלו.

    • 3.5.A.1 שיטה void אינה מחזירה ערך. החוליה שלה מכילה את המפתח void לפני שם השיטה.
    • 3.5.A.2 מתודה שאינה void מחזירה ערך יחיד. הכותרת שלה כוללת את סוג ההחזרה במקום המילת המפתח void.
    • 3.5.A.3 במתודות שאינן void, ביטוי החזרה תואם לסוג ההחזרה מוערך והערך מוחזר. דבר זה מכונה החזרה בערך (return by value).
    • 3.5.A.4 המפתח return משמש להחזרת זרימת הביצועים לנקודה שבה הושעלה השיטה או הקונסטרוקטור. כל קוד הנמצא לאחר פקודת return לא יופעל לעולם. ביצוע פקודת return בתוך ביטוי בחירה או חזרה יפסיק את הביטוי ויצא מהשיטה או מהקונסטרוקטור.
    • 3.5.A.5 מתודת גישה מאפשרת לאובייקטים ממחלקות אחרות לקבל העתק של ערך המשתנים האינסטנציה או משתני המחלקה. מתודת גישה היא מתודה שאינה void.
    • 3.5.A.6 מתודת שינוי (מודיפייר) היא מתודה המשנה את ערכי המשתנים האינסטנציה או משתני המחלקה. מתודת שינוי היא לעיתים קרובות מתודה void.
    • 3.5.A.7 שיטות עם פרמטרים מקבלות ערכים דרך פרמטרים אלו ומשתמשות בערכים אלו כדי לבצע את משימת השיטה.
    • 3.5.A.8 כאשר הארגומנט הוא ערך ראשוני, הפרמטר מצופיין בהעתק של הערך הזה. שינויים בפרמטר אינם משפיעים על הארגומנט המתאים.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    A method has a signature, a return type, and a body. An accessor (getter) 访问器 returns information without changing the object; a mutator (setter) 修改器 changes a field. A method returning a value must have a return of the right type on every path; a void method returns nothing.

    עברית

    לשיטה יש חתימה, סוג החזרה וגוף. אקססור (Getter) מחזיר מידע מבלי לשנות את האובייקט; מיוטטור (Setter) משנה שדה. לשיטה שמחזירה ערך חייב להיות return מהסוג הנכון בכל מסלול; שיטת void לא מחזירה כלום.

    public void setScore(int s) { score = s; }   // mutator
    public String toString() { return name + ": " + score; }
    
    Explore · ⁨חקור⁩

    Follow a method call and its return · ⁨עקוב אחר קריאת מתודה והחזרת הערך⁩

    Calling a method pushes a frame with its parameters; when it hits return, the frame pops and the value goes back to the caller. · ⁨כאשר קוראים מתודה, דוחפים מסגרת עם הפרמטרים שלה; כאשר היא מגיעה לreturn, המסגרת נדחסת והערך חוזר לקורא.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    mutator (setter)/mjuːˈteɪtə/ מוטור (סטטר)
    static (class) variable/ˈstætɪk ˈveərɪəbl/ משתנה סטטי (קלאסי)
    3.6

    Passing and Returning References of an Object · ⁨העברת והשבת רפרנסים של אובייקט⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 3.6.A: Develop code to define behaviors of an object through methods written in a class using object references and determine the result of calling these methods.

    • 3.6.A.1 When an argument is an object reference, the parameter is initialized with a copy of that reference; it does not create a new independent copy of the object. If the parameter refers to a mutable object, the method or constructor can use this reference to alter the state of the object. It is good programming practice to not modify mutable objects that are passed as parameters unless required in the specification.
    • 3.6.A.2 When the return expression evaluates to an object reference, the reference is returned, not a reference to a new copy of the object.
    • 3.6.A.3 Methods cannot access the private data and methods of a parameter that holds a reference to an object unless the parameter is the same type as the method's enclosing class.
    עברית

    מטרות למידה 3.6.A: פיתוח קוד להגדרת התנהגויות של אובייקט באמצעות שיטות שנכתבו בכיתה, תוך שימוש ברפרנסים של אובייקטים, וקביעת התוצאה של קריאת שיטות אלו.

    • 3.6.A.1 כאשר הארגומנט הוא רפרנס של אובייקט, הפרמטר מצופיין בהעתק של הרפרנס הזה; הוא אינו יוצר העתק עצמאי חדש של האובייקט. אם הפרמטר מתייחס לאובייקט מתחלף (mutable), השיטה או הקונסטרוקטור יכולים להשתמש ברפרנס זה כדי לשנות את המצב של האובייקט. מנהג טוב בתכנות הוא לא לשנות אובייקטים מתחלפים שעברו כפרמטרים, אלא אם כן נדרש במפרט.
    • 3.6.A.2 כאשר ביטוי ההחזרה מוערך לרפרנס של אובייקט, הרפרנס מוחזר, ולא רפרנס להעתק חדש של האובייקט.
    • 3.6.A.3 שיטות אינן יכולות לגשת לנתונים פרטיים ולשיטות פרטיות של פרמטר המכיל רפרנס לאובייקט, אלא אם הפרמטר הוא מאותו סוג כמו הכיתה המקיפה את השיטה.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English
    = copies the reference, not the object

    When you pass an object to a method, Java copies the reference, so the method acts on the same object – changes to its fields are visible to the caller. (Primitives are copied by value, so changes to them are not.) A method can also return a reference to an object. Because a String is immutable, passing one is safe; passing a mutable object lets a method change it.

    Exam skill: know that mutating an object's fields inside a method affects the original, but reassigning the parameter (param = new...) does not affect the caller.

    Worked example. Suppose s is a Student with score 50, and we call tweak(s):

    Line (1) changes the object s points to, so the caller now sees 100. Line (2) makes the method's own copy of the reference point at a fresh object – the caller's s is untouched – and line (3) affects only that new object. After the call, s.getScore() is 100: the mutation stuck, the reassignment did not.

    עברית
    = מעתיק את הייחוס, לא את האובייקט

    כשעוברים אובייקט לשיטה, Java מעתיקה את הרפרנס, ולכן השיטה פועלת על האותו אובייקט – שינויים בשדותיו נראים לקורא. (פרימיטיבים מועברים בערך, ולכן שינויים בהם אינם נראים.) שיטה יכולה גם להשיב רפרנס לאובייקט. מכיוון ש-String הוא בלתי משתנה, העברתו בטוחה; העברת אובייקט משתנה מאפשרת לשיטה לשנות אותו.

    Java מעבירה בערך: השיטה מקבלת העתק; העברה אמיתית לפי רפרנס, שאין ל-Java, הייתה מאפשרת לה להחליף את המשתנה של הקורא
    Java תמיד מעבירה בערך (משמאל): השיטה מקבלת העתק של הרפרנס. העברה אמיתית לפי רפרנס (מימין) — שאין ל-Java — הייתה מאפשרת לשיטה להחליף את המשתנה עצמי של הקורא.

    מיומנות למבחן: לדעת שהשמטת שדות של אובייקט בתוך שיטה משפיעה על המקורי, אך החלפת הפרמטר (param = new...) אינה משפיעה על הקורא.

    דוגמה פתורה. נניח ש-s הוא Student עם ציון 50, וקוראים ל-tweak(s):

    public static void tweak(Student a) {
        a.setScore(100);          // (1) mutates the shared object
        a = new Student("Z", 0);  // (2) repoints the local copy only
        a.setScore(5);            // (3) changes only the new local object
    }
    

    השורה (1) משנה את מה שהאובייקט s מצביע אליו, ולכן הקורא רואה כעת את 100. השורה (2) יוצרת העתק פרטית של הייחוס בתוך המטודה שמצביעה אל אובייקט חדש – הייחוס s של הקורא נותר ללא שינוי – והשורה (3) משפיעה רק על אובייקט חדש זה. לאחר השיחה, s.getScore() הוא 100: המוטציה התבצעה, אך ההחזת הייחוס לא.

    3.7

    Class Variables and Class Methods · ⁨משתני מחלקה ומשתני מחלקה (Static Methods)⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 3.7.A: Develop code to define behaviors of a class through class methods.

    • 3.7.A.1 Class methods cannot access or change the values of instance variables or call instance methods without being passed an instance of the class via a parameter.
    • 3.7.A.2 Class methods can access or change the values of class variables and can call other class methods.

    Learning Objective 3.7.B: Develop code to declare the class variables that belong to the class.

    • 3.7.B.1 Class variables belong to the class, with all objects of a class sharing a single copy of the class variable. Class variables are designated with the static keyword before the variable type.
    • 3.7.B.2 Class variables that are designated public are accessed outside of the class by using the class name and the dot operator, since they are associated with a class, not objects of a class.
    • 3.7.B.3 When a variable is declared final, its value cannot be modified.
    עברית

    מטרות למידה 3.7.A: פיתוח קוד להגדרת התנהגויות של כיתה באמצעות שיטות כיתה.

    • 3.7.A.1 שיטות כיתה אינן יכולות לגשת או לשנות את ערכי משתני המוסף או לקרוא לשיטות מוסף ללא קבלת מוסף של הכיתה דרך פרמטר.
    • 3.7.A.2 שיטות כיתה יכולות לגשת או לשנות את ערכי משתני הכיתה ויכולות לקרוא לשיטות כיתה אחרות.

    מטרות למידה 3.7.B: פיתוח קוד להצהרת משתני הכיתה השייכים לכיתה.

    • 3.7.B.1 משתני מחלקה שייכים למחלקה, וכל האובייקטים במחלקה משתפים עותק אחד של משתנה זה. משתני מחלקה מסומנים עם המילאה static לפני סוג המשתנה.
    • 3.7.B.2 משתני מחלקה שמסומנים public נגישים מחוץ למחלקה באמצעות שם המחלקה ואופרטור הנקודה, שכן הם קשורים למחלקה ולא לאובייקטים של המחלקה.
    • 3.7.B.3 כאשר משתנה מוגדר כ-final, הערך שלו אינו ניתן לשינוי.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English
    static vs instance fields

    A static (class) variable 类变量, marked static, is shared by all objects of the class – one copy total (e.g. a counter of how many objects exist). A static method belongs to the class and cannot use instance fields directly. Access them by class name: Student.getCount().

    עברית
    שדות static לעומת שדות instance

    משתנה static (של מחלקה), המסומן static, משותף לכל האובייקטים של המחלקה – העתק אחד בסך הכל (למשל, סופר לכמה אובייקטים קיימים). שיטת static שייכת למחלקה ואינה יכולה להשתמש ישירות בשדות instance. גישה אליהם מתבצעת על ידי שם המחלקה: Student.getCount().

    3.8

    Scope and Access · ⁨תחום (Scope) וגישה⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 3.8.A: Explain where variables can be used in the code.

    • 3.8.A.1 Local variables are variables declared in the headers or bodies of blocks of code. Local variables can only be accessed in the block in which they are declared. Since constructors and methods are blocks of code, parameters to constructors or methods are also considered local variables. These variables may only be used within the constructor or method and cannot be declared to be public or private.
    • 3.8.A.2 When there is a local variable or parameter with the same name as an instance variable, the variable name will refer to the local variable instead of the instance variable within the body of the constructor or method.
    עברית

    מטרת הלמידה 3.8.A: הסבר היכן משתנים יכולים לשמש בקוד.

    • 3.8.A.1 משתנים מקומיים הם משתנים המוגדרים בתוך הכותרות או הגוף של בלוקי קוד. משתנים מקומיים ניתנים לגישה רק בתוך הבלוק שבו הם מוגדרים. מכיוון שבניינים ומתודות הם בלוקי קוד, הפרמטרים לבניינים ולמתודות נחשבים גם הם כמשתנים מקומיים. משתנים אלו יכולים לשמש רק בתוך הבונה או המתודה ואינם יכולים להיות מסומנים כ-public או כ-private.
    • 3.8.A.2 כאשר קיים משתנה מקומי או פרמטר בעל אותו שם כמושתנה מופע, השם יתייחס למשתנה המקומי במקום למשתנה המופע בתוך גוף הבונה או המתודה.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    Scope 作用域 is where a name is visible. A local variable declared in a method exists only inside it; a parameter exists only in its method; an instance variable is visible throughout the object. Access modifiers control visibility across classes: private (this class only) versus public (anywhere). Local variables shadow fields of the same name – a source of bugs.

    עברית

    תחום (Scope) הוא המקום שבו שם נתון נראה. משתנה מקומי שהוכרז בתוך שיטה קיים רק בתוכה; פרמטר קיים רק בשיטה שלו; משתנה instance נראה בכל האובייקט. מודפי גישה שולטים בנראות בין מחלקות: private (המחלקה הזו בלבד) מול public (בכל מקום). משתנים מקומיים מסתרים (Shadow) שדות באותו שם – זהו מקור ל bugs.

    משתנה גלובלי נראה בכל מקום; משתנה לוקאלי רק בתוך הבלוק שלו
    משתנה גלובלי נראה בכל מקום; משתנה מקומי רק בתוך הבלוק שלו
    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Scope/skəʊp/ תחום תוקף
    3.9

    The this Keyword · ⁨המילה המפורשת this⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 3.9.A: Develop code for expressions that are self-referencing and determine the result of these expressions.

    • 3.9.A.1 Within an instance method or a constructor, the keyword this acts as a special variable that holds a reference to the current object—the object whose method or constructor is being called.
    • 3.9.A.2 The keyword this can be used to pass the current object as an argument in a method call.
    • 3.9.A.3 Class methods do not have a this reference.
    עברית

    מטרת הלמידה 3.9.A: פיתוח קוד עבור ביטויים המפנים לעצמם וקביעת התוצאה של ביטויים אלו.

    • 3.9.A.1 בתוך מתודת מופע או בונה, המילה this פועלת כמשתנה מיוחד המשמר הפניה לאובייקט הנוכחי—האובייקט שמתודתו או בונהו נקראים.
    • 3.9.A.2 המילה this יכולה לשמש להעברת האובייקט הנוכחי כארגומנט בקריאת מתודה.
    • 3.9.A.3 מתודות מחלקה אינן מכילות הפניה ל-this.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    this is a reference to the current object. Use it to tell a field apart from a parameter with the same name, or to call another method of the same object:

    Exam skill: when a constructor or setter's parameter has the same name as a field, you must write this.field = param – without this, the assignment does nothing useful.

    עברית

    this הוא רפרנס לאובייקט הנוכחי. ניתן להשתמש בו כדי להבדיל בין שדה לבין פרמטר באותו שם, או לקרוא לשיטה אחרת באותו אובייקט:

    public Student(String name, int score) {
        this.name = name;      // this.name is the field; name is the parameter
        this.score = score;
    }
    

    מיומנות למבחן: כאשר לפרמטר של Constructor או Setter יש אותו שם כמו לשדה, חובה לכתוב this.field = param – ללא this, ההקלדה אינה עושה דבר שימושי.

    3.9

    Exam tips · ⁨טיפים לבחינות⁩

    English
    • Design with methods and classes: encapsulate data as private fields and expose behaviour through public methods.
    • Know the difference between an object and its class, and that objects are passed by value — the parameter gets a copy of the reference, so a method can change the object's state, but reassigning the parameter does not affect the caller (Java has no pass-by-reference).
    • Traverse arrays and ArrayLists safely — size is length vs .size(), and removing during a loop shifts indices.
    • Trace a recursive method to determine its result: find the base case first, then follow each recursive call to its return value (writing recursive code is outside the exam's scope).
    • Recognise inheritance vocabulary — superclass, subclass, method overriding, and that every class is a subclass of Object (designing and implementing inheritance is outside the exam's scope).
    עברית
    • עיצוב עם שיטות וכיתות: אקפסולציה נתונים כשדות private וחשיפת התנהגות דרך שיטות ציבוריות.
    • להבין את ההבדל בין אובייקט לכיתה שלו, ולעובדה שאובייקטים עוברים ערך — הפרמטר מקבל העתק של הייחוס, כך ששיטה יכולה לשנות את מצב האובייקט, אך השבתת התייחסות בפרמטר אינה משפיעה על הקורא (ב-Java אין מעבר בהפניה).
    • לעבור על מערכים ועל ArrayList בטוח — הגודל הוא length מול .size(), והסרה במהלך לולאה מזיזה את האינדקסים.
    • מעקב בשיטה רקורסיבית כדי לקבוע תוצאתה: למצוא תחילה את המקרה הבסיסי, ולאחר מכן לעקוב אחרי כל קריאה רקורסיבית עד לתוצאת החזרה (כתיבת קוד רקורסיבי היא מחוץ להיקף המבחן).
    • לזהות מושגי ירישה: כיתה עליונה, כיתה תחתונה, חפיסת שיטה, וכל כיתה היא כיתה תחתונה של Object (עיצוב והטמעת ירישה הם מחוץ להיקף המבחן).
  • 4

    Data Collections · ⁨אוספי נתונים⁩

    Watch lesson · ⁨צפה בשיעור⁩
    4.1

    The Ethics of Collecting Data · ⁨אתיקה באיסוף נתונים⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.1.A: Explain the risks to privacy from collecting and storing personal data on computer systems.

    • 4.1.A.1 When using a computer, personal privacy is at risk. When developing new programs, programmers should attempt to safeguard the personal privacy of the user.

    Learning Objective 4.1.B: Explain the importance of recognizing data quality and potential issues when using a data set.

    • 4.1.B.1 Algorithmic bias describes systemic and repeated errors in a program that create unfair outcomes for a specific group of users.
    • 4.1.B.2 Programmers should be aware of the data set collection method and the potential for bias when using this method before using the data to extrapolate new information or drawing conclusions.
    • 4.1.B.3 Some data sets are incomplete or contain inaccurate data. Using such data in the development or use of a program can cause the program to work incorrectly or inefficiently.

    Learning Objective 4.1.C: Identify an appropriate data set to use in order to solve a problem or answer a specific question.

    • 4.1.C.1 Contents of a data set might be related to a specific question or topic and might not be appropriate to give correct answers or extrapolate information for a different question or topic.
    עברית

    מטרת הלמידה 4.1.A: הסבר הסיכונים לפרטיות הנובעים מאיסוף ואחסון נתונים אישיים על מערכות מחשב.

    • 4.1.A.1 בעת שימוש במחשב, הפרטיות האישית נמצאת בסכנה. בפיתוח תוכנות חדשות, תוכנתנים צריכים לנסות לשמור על פרטיות המשתמש.

    מטרת הלמידה 4.1.B: הסבר החשיבות בהכרה באיכות הנתונים ובבעיות אפשריות בעת שימוש במאגר נתונים.

    • 4.1.B.1 הטיה אלגוריתמית מתארת טעויות מערכתיות ומחוזקות בתוכנה היוצרות תוצאות לא הוגנות עבור קבוצת משתמשים ספציפית.
    • 4.1.B.2 תוכנתנים צריכים להיות מודעים לשיטת איסוף הנתונים ולסיכון ההטיה בעת שימוש בשיטה זו, לפני השימוש בנתונים לחילוץ מידע חדש או למסקנות.
    • 4.1.B.3 חלק ממאגרי הנתונים הם חסרים או מכילים נתונים לא מדויקים. שימוש בנתונים כאלה בפיתוח או בשימוש בתוכנה עלול לגרום לתוכנה לפעול בצורה לא נכונה או לא יעילה.

    מטרת הלמידה 4.1.C: זיהוי מאגר נתונים מתאים לשימוש כדי לפתור בעיה או לענות על שאלה ספציפית.

    • 4.1.C.1 תוכן ערכי הנתונים עשוי להיות קשור לשאלה או נושא ספציפי ועשוי לא להיות מתאים למתן תשובות נכונות או להסקת מידע לשאלה או נושא אחרים.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    Programs that gather data raise questions of privacy 隐私 and consent 同意. Collect only what is needed, protect it, and be honest about its use. Data can carry bias 偏见 if it does not represent everyone fairly, leading to unfair results – a responsibility that comes with storing information.

    עברית
    מארזי שרתים במרכז נתונים — אוסף נתונים גדול מעלה שאלות אתיות לגבי איסוף ושימוש
    מארזי שרתים במרכז נתונים — אוסף נתונים גדול מעלה שאלות אתיות לגבי איסוף ושימוש

    תוכניות שמאספות נתונים מעלות שאלות של פרטיות והסכמה. יש לאסוף רק מה שנדרש, לשמור עליו ולהיות כנים לגבי השימוש בו. נתונים יכולים לשאת טייט אם הם אינם מייצגים את כולם באופן הוגן, מה שמוביל לתוצאות לא הוגנות – אחריות זו נובעת מאחסון מידע.

    4.2

    Why We Need Data Structures · ⁨מדוע אנו זקוקים למבני נתונים⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.2.A: Represent patterns and algorithms that involve data sets found in everyday life using written language or diagrams.

    • 4.2.A.1 A data set is a collection of specific pieces of information or data.
    • 4.2.A.2 Data sets can be manipulated and analyzed to solve a problem or answer a question. When analyzing data sets, values within the set are accessed and utilized one at a time and then processed according to the desired outcome.
    • 4.2.A.3 Data can be represented in a diagram by using a chart or table. This visual can be used to plan the algorithm that will be used to manipulate the data.
    עברית

    מטרת הלמידה 4.2.A: להציג דפוסים ואלגוריתמים המשתמשים במאגרי נתונים הנמצאים בחיי היומיום באמצעות כתיבה או דיאגרמות.

    • 4.2.A.1 מאגר נתונים הוא אוסף של פרטי מידע או נתונים ספציפיים.
    • 4.2.A.2 ניתן לבצע עיבוד וניתוח על מאגרי נתונים כדי לפתור בעיה או לענות על שאלה. בעת ניתוח מאגרי נתונים, הערכים בתוך המאגר נגישים ומשתמשים בהם אחד-אחד, ולאחר מכן מעובדים בהתאם לתוצאה הרצויה.
    • 4.2.A.3 ניתן לייצג נתונים בדיאגרמה באמצעות טבלה או גרף. תוכן ויזואלי זה יכול לשמש לתכנון האלגוריתם שיישמש לעיבוד הנתונים.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    A single variable holds one value; real problems need to store many related values – a class roster, pixels, sensor readings. A data structure 数据结构 organizes a collection so we can store, find, and process items efficiently. The AP course uses three: the array, the ArrayList, and the 2D array.

    עברית
    ארון תיקיות: אוספים מאחסנים ערכים רבים תחת שם אחד כדי שהאלגוריתמים יוכלו לעבדם
    ארון תיקיות: אוספים מאחסנים ערכים רבים תחת שם אחד כדי שהאלגוריתמים יוכלו לעבדם

    משתנה אחד מחזיק ערך אחד; בעיות אמיתיות דורשות אחסון של מספר רב של ערכים קשורים – רשימת תלמידים, פיקסלים, קריאות חיישנים. מבנה נתונים מארגן קבוצה כך נוכל לאחסן, למצוא ולעבד פריטים ביעילות. הקורס AP משתמש בשלושה: מערך, ArrayList, ו-מערך דו-ממדי ⟨2⟩.

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    privacy/ˈprɪvəsi/ פרטיות
    consent/kənˈsent/ הסכמה
    bias/ˈbaɪəs/ שיפוטיות
    data structure/ˈdeɪtə ˈstrʌktʃə/ מבנה נתונים
    array/əˈreɪ/ מערך
    Traverse/trəˈvɜːs/ עבר
    ArrayList/əˈreɪ lɪst/ ArrayList
    2D array/ˌtuː ˈdiː əˈreɪ/ מערך 2D
    row-major order/rəʊ ˈmeɪdʒə ˈɔːdə/ סדר תלת-ממדי לפי שורות (row-major order)
    4.3

    Making and Reading an Array · ⁨יצירת וקריאה ממערך⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.3.A: Develop code used to represent collections of related data using one-dimensional (1D) array objects.

    • 4.3.A.1 An array stores multiple values of the same type. The values can be either primitive values or object references.
    • 4.3.A.2 The length of an array is established at the time of creation and cannot be changed. The length of an array can be accessed through the length attribute.
    • 4.3.A.3 When an array is created using the keyword new, all of its elements are initialized to the default values for the element data type. The default value for int is 0, for double is 0.0, for boolean is false, and for a reference type is null.
    • 4.3.A.4 Initializer lists can be used to create and initialize arrays.
    • 4.3.A.5 Square brackets [ ] are used to access and modify an element in a 1D array using an index.
    • 4.3.A.6 The valid index values for an array are 0 through one less than the length of the array, inclusive. Using an index value outside of this range will result in an ArrayIndexOutOfBoundsException.
    עברית

    מטרת הלמידה 4.3.A: פיתוח קוד המשמש לייצוג אוספים של נתונים קשורים באמצעות אובייקטי מערך חד-ממדי (1D).

    • 4.3.A.1 מערך מאחסן מספר ערכים מאותו סוג. הערכים יכולים להיות ערכים ראשוניים או הפניות לאובייקטים.
    • 4.3.A.2 אורך המערך נקבע בזמן היצירה ואינו ניתן לשינוי. ניתן לגשת לאורך המערך באמצעות ה-stalength attribute.
    • 4.3.A.3 כאשר מערך נוצר באמצעות המילה new, כל האלמנטים שלו מוגדרים לערכים ברירת מחדל של סוג הנתונים של האלמנט. הערך הרירת מחדל עבור int הוא 0, עבור double הוא 0.0, עבור boolean הוא false, ועבור סוג הפניה הוא null.
    • 4.3.A.4 ניתן להשתמש ברשימות מתחילים (initializer lists) ליצור ולאתחל מערכים.
    • 4.3.A.5 סוגריים מרובעים [ ] משמשים לגישה ולשינוי של אלמנט במערכת בעל-ממד 1 באמצעות אינדקס.
    • 4.3.A.6 ערכי האינדקס תקפים למערך הם 0 ועד אחת פחות מאורך המערך, כולל. שימוש בערך אינדקס מחוץ לטווח זה יוביל ל-staArrayIndexOutOfBoundsException.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    An array 数组 is a fixed-size, ordered collection of same-type values. Indices run from 0 to length - 1:

    Accessing an index outside 0..length-1 throws an ArrayIndexOutOfBoundsException.

    עברית

    מערך הוא אוסף מסודר בגודל קבוע של ערכים מאותו סוג. האינדקסים נעים מ-0 עד length - 1:

    מערך חד-ממדי (רשימה) עם האינדקסים והגבולות שלו
    מערך חד-ממדי (רשימה) עם האינדקסים והגבולות שלו
    int[] nums = new int[5];        // five zeros
    int[] vals = {3, 1, 4, 1, 5};   // initialized
    int first = vals[0];            // 3
    int n = vals.length;            // 5 (a field, not a method)
    

    ניסיון לגשת לאינדקס מחוץ ל-0..length-1 גורם לשגיאת ArrayIndexOutOfBoundsException.

    4.4

    Visiting Every Element of an Array · ⁨ביקור בכל אלמנט במערך⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.4.A: Develop code used to traverse the elements in a 1D array and determine the result of these traversals.

    • 4.4.A.1 Traversing an array is when repetition statements are used to access all or an ordered sequence of elements in an array.
    • 4.4.A.2 Traversing an array with an indexed for loop or while loop requires elements to be accessed using their indices.
    • 4.4.A.3 An enhanced for loop header includes a variable, referred to as the enhanced for loop variable. For each iteration of the enhanced for loop, the enhanced for loop variable is assigned a copy of an element without using its index.
    • 4.4.A.4 Assigning a new value to the enhanced for loop variable does not change the value stored in the array.
    • 4.4.A.5 When an array stores object references, the attributes can be modified by calling methods on the enhanced for loop variable. This does not change the object references stored in the array.
    • 4.4.A.6 Code written using an enhanced for loop to traverse elements in an array can be rewritten using an indexed for loop or a while loop.
    עברית

    מטרת למידה 4.4.A: פיתוח קוד המשמש לעבור על אלמנטים במערכת בעל-ממד 1 וקביעת תוצאת מעברים אלו.

    • 4.4.A.1 עברת מערך היא שימוש בפקודות חזרה כדי לגשת לכל האלמנטים או לסדרה מסודרת של אלמנטים במערך.
    • 4.4.A.2 עברת מערך באמצעות לולאת אינדקס for או לולאת while דורשת גישה לאלמנטים באמצעות האינדקסים שלהם.
    • 4.4.A.3 ראש לולאת增强ed (enhanced) for כולל משתנה, המכונה משתנה לולאת增强ed (enhanced) for. בכל איטרציה של לולאת增强ed (enhanced) for, משתנה לולאת增强ed (enhanced) for מקבל העתק של אלמנט ללא שימוש באינדקס שלו.
    • 4.4.A.4 הקצאת ערך חדש למשתנה לולאת增强ed (enhanced) for אינה משנה את הערך המאוחסן במערך.
    • 4.4.A.5 כאשר מערך מאחסן רפרנסים לאובייקטים, ניתן לשנות את התכונות על ידי קריאת מეთודים על משתנה לולאת增强ed (enhanced) for. הדבר אינו משנה את הרפרנסים לאובייקטים המאוחסנים במערך.
    • 4.4.A.6 קוד שכתוב באמצעות לולאת增强ed (enhanced) for לעבור על אלמנטים במערך יכול להיות מושב באמצעות לולאת אינדקס for או לולאת while.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    Traverse 遍历 an array with a for loop (gives the index) or an enhanced for / for-each loop (gives each value, read-only):

    עברית

    מעבר במערך באמצעות לולאת for (נותנת את האינדקס) או לולאת enhanced for / for-each (נותנת כל ערך, לקריאה בלבד):

    for (int i = 0; i < a.length; i++) { a[i] *= 2; }   // can modify
    for (int v : a) { System.out.println(v); }          // read each value
    
    4.5

    Standard Array Algorithms · ⁨אלגוריתמים סטנדרטיים למערכות⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.5.A: Develop code for standard and original algorithms for a particular context or specification that involves arrays and determine the result of these algorithms.

    • 4.5.A.1 There are standard algorithms that utilize array traversals to:
      • determine a minimum or maximum value
      • compute a sum or average
      • determine if at least one element has a particular property
      • determine if all elements have a particular property
      • determine the number of elements having a particular property
      • access all consecutive pairs of elements
      • determine the presence or absence of duplicate elements
      • shift or rotate elements left or right
      • reverse the order of the elements
    עברית

    מטרת הלמידה 4.5.A: פיתוח קוד לאלגוריתמים סטנדרטיים וחדשים בהקשר או ספציפיקציה נתונים המעורבים במערכים, והחלטת תוצאות האלגוריתמים הללו.

    • 4.5.A.1 קיימים אלגוריתמים סטנדרטיים המשתמשים בעברות מערך עבור:
      • קביעת ערך מינימום או מקסימום
      • חישוב סכום או ממוצע
      • לקבוע אם לפחות אלמנט אחד בעל תכונה מסוימת
      • לקבוע אם לכל האלמנטים יש תכונה מסוימת
      • לקבוע את מספר האלמנטים שיש להם תכונה מסוימת
      • לגשת לכל הזוגות הרצופים של אלמנטים
      • לקבוע את נוכחותם או היעדרם של אלמנטים כפולים
      • להזיז או לסובב אלמנטים שמאלה או ימינה
      • להפוך את הסדר של האלמנטים

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    Master these patterns: compute a sum or average, find the max/min, count items meeting a condition, check for a duplicate, and reverse or shift elements. Each is a traversal with a running result:

    עברית

    שלוו את הדפוסים האלה: חשב סכום או ממוצע, מצא את ה-מקסימום/מינימום, ספר פריטים העומדים בתנאי מסוים, בדוק נוכחות של כפילות, והפוך או הזז רכיבים. כל אחד מהם הוא טרברסיה עם תוצאה מצטברת:

    int sum = 0;
    for (int v : a) sum += v;
    double avg = (double) sum / a.length;
    
    4.6

    Reading Data from a Text File · ⁨קריאת נתונים מקובץ טקסט⁩

    Syllabus · ⁨סיילבוס⁩
    Learning ObjectiveEssential Knowledge

    4.6.A
    Develop code to read data from a text file.

    • 4.6.A.1 A file is storage for data that persists when the program is not running. The data in a file can be retrieved during program execution.
    • 4.6.A.2 A file can be connected to the program using the File and Scanner classes.
    • 4.6.A.3 A file can be opened by creating a File object, using the name of the file as the argument of the constructor.
      • File(String str) is the File constructor that accepts a String file name to open for reading, where str is the pathname for the file.
    • 4.6.A.4 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.
    • 4.6.A.5 The File and IOException classes are part of the java.io package. An import statement must be used to make these classes available for use in the program.
    • 4.6.A.6 The following Scanner methods and constructor—including what they do and when they are used—are part of the Java Quick Reference:
      • Scanner(File f) is the Scanner constructor that accepts a File for reading.
      • int nextInt() returns the next int read from the file or input source if available. If the next int does not exist or is out of range, it will result in an InputMismatchException.
      • 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.
      • 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.
      • String nextLine() returns the next line of text as a String read from the file or input source; can return the empty string if called immediately after another Scanner method that is reading from the file or input source.
      • String next() returns the next String read from the file or input source.
      • boolean hasNext() returns true if there is a next item to read in the file or input source; returns false otherwise.
      • void close() closes this scanner.
      • Exclusion statement: Accepting input from the keyboard is outside the scope of the AP Computer Science A course and exam.
    • 4.6.A.7 Using nextLine and the other Scanner methods together on the same input source sometimes requires code to adjust for the methods' different ways of handling whitespace.
      • Exclusion statement: Writing or analyzing code that uses both nextLine and other Scanner methods on the same input source is outside the scope of the AP Computer Science A course and exam.
    • 4.6.A.8 The following additional String method—including what it does and when it is used—is part of the Java Quick Reference:
      • String[] split(String del) returns a String array where each element is a substring of this String, which has been split around matches of the given expression del.
      • Exclusion statement: The parameter del uses a format called a regular expression. Writing or analyzing code that uses any of the special properties of regular expressions (e.g., \\*, \\.) is outside the scope of the AP Computer Science A course and exam.
    • 4.6.A.9 A while loop can be used to detect if the file still contains elements to read by using the hasNext method as the condition of the loop.
    • 4.6.A.10 A file should be closed when the program is finished using it. The close method from Scanner is called to close the file.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    File and IOException live in java.io, so a program that reads a file needs import java.io.*;. Opening a file can fail (it might not exist), and Java forces you to handle that – the simplest way is to add throws IOException to the method header. A Scanner then reads the file line by line, using hasNext... to test before reading:

    Reading typed tokens with nextInt(), nextDouble(), or nextBoolean() throws an InputMismatchException if the next token is the wrong type – for example calling nextInt() when the next thing in the file is the word cat.

    עברית

    File ו-IOException חיים ב-java.io, לכן תוכנית הקוראת קובץ זקוקה ל-import java.io.*;. פתיחת קובץ עלולה להיכשל (הוא עשוי לא להיות קיים), ו-Java מחייבת אותך לטפל בכך – הדרך הפשוטה ביותר היא להוסיף throws IOException לחתימת המетודה. Scanner קורא אחר כך את הקובץ שורה בשורה, תוך שימוש ב-hasNext... לבדיקה לפני הקריאה:

    import java.io.*;
    ...
    public static void readFile() throws IOException {
        Scanner f = new Scanner(new File("data.txt"));
        while (f.hasNextLine()) {
            String line = f.nextLine();
        }
    }
    

    קריאת טוקנים מעוגנים עם nextInt(), nextDouble() או nextBoolean() מייצרת InputMismatchException אם הטוקן הבא הוא מהסוג הלא נכון – לדוגמה קריאת nextInt() כאשר הדבר הבא בקובץ הוא המילה cat.

    4.7

    Wrapping a Number in an Object · ⁨עטיפת מספר באובייקט⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.7.A: Develop code to use Integer and Double objects from their primitive counterparts and determine the result of using these objects.

    • 4.7.A.1 The Integer class and Double class are part of the java.lang package. An Integer object is immutable, meaning once an Integer object is created, its attributes cannot be changed. A Double object is immutable, meaning once a Double object is created, its attributes cannot be changed.
    • 4.7.A.2 Autoboxing is 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
      • assigned to a variable of the corresponding wrapper class
    • 4.7.A.3 Unboxing is 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
      • assigned to a variable of the corresponding primitive type
    • 4.7.A.4 The following class Integer method—including what it does and when it is used—is part of the Java Quick Reference:
      • static int parseInt(String s) returns the String argument as an int.
    • 4.7.A.5 The following class Double method—including what it does and when it is used—is part of the Java Quick Reference:
      • static double parseDouble(String s) returns the String argument as a double.
    עברית

    מטרת למידה 4.7.A: פיתוח קוד לשימוש בInteger ובאובייקטי Double ממקבילותיהן הפרימיטיביות וקביעת תוצאת השימוש באובייקטים אלו.

    • 4.7.A.1 המחלקה Integer והמחלקה Double הן חלק מארכיון java.lang. אובייקט Integer הוא בלתי-מתחלף (immutable), כלומר לאחר יצירת אובייקט Integer, תכונותיו אינן ניתנות לשינוי. אובייקט Double הוא בלתי-מתחלף, כלומר לאחר יצירת אובייקט Double, תכונותיו אינן ניתנות לשינוי.
    • 4.7.A.2 Autoboxing הוא ההמרה האוטומטית שמבצע מחלקת Java בין סוגים פרימיטיביים למחלקות העטיפה המתאימות שלהן. הדבר כולל המרת int לInteger והמרת double לDouble. מחלקת Java מפעילה autoboxing כאשר ערך פרימיטיבי הוא:
      • עובר כפרמטר לשיטה שמצפה לאובייקט מהמחלקה העטיפה (wrapper class) המתאימה
      • מוקצה למשתנה מהמחלקה העטיפה (wrapper class) המתאימה
    • 4.7.A.3 Unboxing הוא ההמרה האוטומטית שמבצע מחלקת Java ממחלקת העטיפה לסוג הפרימיטיבי. הדבר כולל המרת Integer לint והמרת Double לdouble. מחלקת Java מפעילה unboxing כאשר אובייקט ממחלקת עטיפה הוא:
      • עובר כפרמטר לשיטה שמצפה לערך מהסוג הגולמי (primitive type) המתאים
      • מוקצה למשתנה מהסוג הגולמי (primitive type) המתאים
    • 4.7.A.4 מתודת Integer הקלאס הבאה—כולל מה היא עושה ומתי משתמשים בה—חלק מההפניה המהירה ל-Java:
      • static int parseInt(String s) מחזירה את הארגומנט String כ-int.
    • 4.7.A.5 מתודת Double הקלאס הבאה—כולל מה היא עושה ומתי משתמשים בה—חלק מההפניה המהירה ל-Java:
      • static double parseDouble(String s) מחזירה את הארגומנט String כ-double.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    An ArrayList stores objects, not primitives, so a primitive is wrapped in an object: Integer wraps int, Double wraps double. Java does this with autoboxing 自动装箱 (int to Integer) and unboxing (back again) automatically, so you can write list.add(5) and int x = list.get(0).

    עברית

    ArrayList מאחסן אובייקטים, ולא טיפים ראשוניים, ולכן טיפ ראשוני מועטף בתוך אובייקט: Integer מעטף את int, Double מעטף את double. Java עושה זאת באמצעות autoboxing (מ-int ל-Integer) ו-unboxing (חזרה לאחור) אוטומטית, כך שניתן לכתוב list.add(5) ו-int x = list.get(0).

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    autoboxing/ˌɔːtəʊˈbɒksɪŋ/ אוטובוקסינג
    4.8

    The ArrayList Toolbox · ⁨ערכת הכלים של ArrayList⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.8.A: Develop code for collections of related objects using ArrayList objects and determine the result of calling methods on these objects.

    • 4.8.A.1 An ArrayList object is mutable in size and contains object references.
    • 4.8.A.2 The ArrayList constructor ArrayList() constructs an empty list.
    • 4.8.A.3 Java allows the generic type ArrayList<E>, where the type parameter E specifies the type of the elements. When ArrayList<E> is specified, the types of the reference parameters and return type when using the ArrayList methods are type E. ArrayList<E> is preferred over ArrayList. For example, ArrayList<String> names = new ArrayList<String>(); allows the compiler to find errors that would otherwise be found at run-time.
    • 4.8.A.4 The ArrayList class is part of the java.util package. An import statement must be used to make this class available for use in the program.
    • 4.8.A.5 The following ArrayList methods—including what they do and when they are used—are part of the Java Quick Reference:
      • int size() returns the number of elements in the list.
      • boolean add(E obj) appends obj to end of list; returns true.
      • void add(int index, E obj) inserts obj at position index (0 <= index <= size), moving elements at position index and higher to the right (adds 1 to their indices) and adds 1 to size.
      • E get(int index) returns the element at position index in the list.
      • E set(int index, E obj) replaces the element at position index with obj; returns the element formerly at position index.
      • E remove(int index) removes element from position index, moving elements at position index + 1 and higher to the left (subtracts 1 from their indices) and subtracts 1 from size; returns the element formerly at position index.
    • 4.8.A.6 The indices for an ArrayList start at 0 and end at the number of elements - 1.
    עברית

    מטרת הלמידה 4.8.A: פיתוח קוד לקולקציות של אובייקטים קשורים באמצעות אובייקטי ArrayList וקביעת התוצאה של קריאת מתודות על אובייקטים אלו.

    • 4.8.A.1 אובייקט ArrayList הוא משתנה בגודלו ומכיל רעיונות לאובייקטים.
    • 4.8.A.2 בונה ArrayList ArrayList() בונה רשימה ריקה.
    • 4.8.A.3 Java מאפשרת את הסוג הגנרי ArrayList<E>, שבו הפרמטר E מצין את סוג האלמנטים. כאשר ArrayList<E> מצויין, סוגי פרמטרי הרעיון והסוג ההחזרתי בעת שימוש במתודות ArrayList הם סוג E. ArrayList<E> מועדף על פני ArrayList. לדוגמה, ArrayList<String> names = new ArrayList<String>(); מאפשר למורכב להציג שגיאות שהיו נמצאות רק בזמן הרצה.
    • 4.8.A.4 הקלאס ArrayList חלק ממארגון java.util. צריך להשתמש בהצהרה import כדי להפוך קלאס זה לזמין לשימוש בתוכנית.
    • 4.8.A.5 מתודות ArrayList הבאות—כולל מה הן עושות ומתי משתמשים בהן—חלק מההפניה המהירה ל-Java:
      • int size() מחזירה את מספר האלמנטים ברשימה.
      • boolean add(E obj) מוסיף obj בסוף הרשימה; מחזיר true.
      • void add(int index, E obj) מכניס obj במיקום index (0 <= index <= size), מזיז אלמנטים במיקום index ובגבוה יותר ימינה (מוסיף 1 למדגמאות שלהם) ומוסיף 1 לגודל.
      • E get(int index) מחזירה את האלמנט במיקום index ברשימה.
      • E set(int index, E obj) מחליף את האלמנט במיקום index ב-obj; מחזיר את האלמנט ששכן בעבר במיקום index.
      • E remove(int index) מסיר אלמנט ממיקום index, מזיז אלמנטים במיקום index + 1 ובגבוה יותר שמאלה (מפחית 1 מדגמאות שלהם) ומפחית 1 מגודל; מחזיר את האלמנט שהיה במקום index לפני כן.
    • 4.8.A.6 הדגמאות עבור ArrayList מתחילות ב-0 ומסתיימות במספר האלמנטים - 1.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English
    What an ArrayList really is

    An ArrayList 动态数组 grows and shrinks as you add or remove items. Declare it with the element type in <>:

    עברית
    מהו reallyArrayList

    ArrayList גדל וקטן כשמוסיפים או מורידים פריטים. הצהר אותו עם סוג האלמנט ב-<>:

    ArrayList<String> names = new ArrayList<String>();
    names.add("Amy");           // append
    names.add(0, "Bob");        // insert at index
    names.get(0);               // read
    names.set(1, "Cara");       // replace
    names.remove(0);            // delete, shifts the rest left
    names.size();               // count (a method, unlike array.length)
    
    4.9

    Visiting Every Element of an ArrayList · ⁨סיור בכל רכיב של ArrayList⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.9.A: Develop code used to traverse the elements of an ArrayList and determine the results of these traversals.

    • 4.9.A.1 Traversing an ArrayList is when iteration or recursive statements are used to access all or an ordered sequence of the elements in an ArrayList.
    • 4.9.A.2 Deleting elements during a traversal of an ArrayList requires the use of special techniques to avoid skipping elements.
    • 4.9.A.3 Attempting to access an index value outside of its range will result in an IndexOutOfBoundsException.
    • 4.9.A.4 Changing the size of an ArrayList while traversing it using an enhanced for loop can result in a ConcurrentModificationException. Therefore, when using an enhanced for loop to traverse an ArrayList, you should not add or remove elements.
    עברית

    מטרת למידה 4.9.A: פיתוח קוד לביצוע איטרציה על מילויי ArrayList וקביעת תוצאות האיטרציות הללו.

    • 4.9.A.1 ביצוע איטרציה על ArrayList מתרחש כאשר משתמשים בפקודות איטרציה או רקורסיביות כדי לגשת לכל המילויים או לסדרה מסודרת מהם ב-ArrayList.
    • 4.9.A.2 מחיקת מילויים במהלך איטרציה על ArrayList דורשת שימוש בטכניקות ייעודיות כדי למנוע דילוג על מילויים.
    • 4.9.A.3 ניסיון לגשת לערך אינדקס החוצה מתחום התקף שלו יוביל ל-IndexOutOfBoundsException.
    • 4.9.A.4 שינוי גודל של ArrayList במהלך איטרציה באמצעות לולאת for מוגברת עשויה להוביל ל-ConcurrentModificationException. לכן, בעת שימוש בלולאת for מוגברת לביצוע איטרציה על ArrayList, אין להוסיף או להסיר מילויים.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    Traverse with an index loop or a for-each loop, just like arrays (use size() and get(i)):

    Exam skill: when removing items in an index loop, either loop backwards or do not increment i after a removal – otherwise removing shifts elements left and you skip one. And never add or remove elements while traversing an ArrayList with a for-each loop: changing its size mid-loop throws a ConcurrentModificationException, so use an index loop (backwards, as above) whenever you must remove.

    עברית

    טרברס עם לולאת אינדקס או לולאת for-each, בדיוק כמו במערכות (שתמש ב-size() ו-get(i)):

    for (int i = 0; i < list.size(); i++) { ... list.get(i) ... }
    for (String s : list) { ... }
    

    מיומנות לבחינה: כאשר מסיר פריטים בלולאת אינדקס, או שמלולאת הפוכה או שלא מעלים את i לאחר הרדה – אחרת ההסרה מזיזה רכיבים שמאלה ומדלגים על אחד. ואין להוסיף או להסיר רכיבים בזמן טרברסיה של ArrayList עם לולאת for-each: שינוי הגודל במהלך הלולאה מייצר ConcurrentModificationException, לכן השתמש בלולאת אינדקס (הפוכה, כפי שצוין לעיל) בכל פעם שיש להסיר.

    4.10

    Standard ArrayList Algorithms · ⁨אלגוריתמים סטנדרטיים של ArrayList⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.10.A: Develop code for standard and original algorithms for a particular context or specification that involve ArrayList objects and determine the result of these algorithms.

    • 4.10.A.1 There are standard ArrayList algorithms that utilize traversals to:
      • determine a minimum or maximum value
      • compute a sum or average
      • determine if at least one element has a particular property
      • determine if all elements have a particular property
      • determine the number of elements having a particular property
      • access all consecutive pairs of elements
      • determine the presence or absence of duplicate elements
      • shift or rotate elements left or right
      • reverse the order of the elements
      • insert elements
      • delete elements
    • 4.10.A.2 Some algorithms require multiple String, array, or ArrayList objects to be traversed simultaneously.
    עברית

    מטרות למידה 4.10.A: פיתוח קוד לאלגוריתמים סטנדרטיים וחדשניים עבור הקשר או מפרט מסוים המעורבים בArrayList אובייקטים והחלטת התוצאה של אלגוריתמים אלו.

    • 4.10.A.1 ישנם אלגוריתמים סטנדרטיים ArrayList המשתמשים במעברים כדי:
      • קביעת ערך מינימום או מקסימום
      • חישוב סכום או ממוצע
      • לקבוע אם לפחות אלמנט אחד בעל תכונה מסוימת
      • לקבוע אם לכל האלמנטים יש תכונה מסוימת
      • לקבוע את מספר האלמנטים שיש להם תכונה מסוימת
      • לגשת לכל הזוגות הרצופים של אלמנטים
      • לקבוע את נוכחותם או היעדרם של אלמנטים כפולים
      • להזיז או לסובב אלמנטים שמאלה או ימינה
      • להפוך את הסדר של האלמנטים
      • להכניס אלמנטים
      • למחוק אלמנטים
    • 4.10.A.2 חלק מהאלגוריתמים דורשים מעבר סימולטני על מספר String, אובייקט מארץ, או ArrayList.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    The same algorithms as arrays – max/min, count, sum – plus insertion and deletion that arrays cannot do easily. A common task is to remove all elements matching a condition, handling the index-shift carefully.

    עברית

    אותם אלגוריתמים כמו במערכות – מקסימום/מינימום, ספירה, סכום – בנוסף להוספה והסרה שאין ביצוען קל במערכות. משימה נפוצה היא להסיר את כל האלמנטים העומדים בתנאי מסוים, תוך טיפול זהיר בהזזת האינדקס.

    4.11

    Grids: Two-Dimensional Arrays · ⁨רשתות: מערכות דו-ממדיות⁩

    Syllabus · ⁨סיילבוס⁩
    Learning ObjectiveEssential Knowledge

    4.11.A
    Develop code used to represent collections of related data using two-dimensional (2D) array objects.

    • 4.11.A.1 A 2D array is stored as an array of arrays. Therefore, the way 2D arrays are created and indexed is similar to 1D array objects. The size of a 2D array is established at the time of creation and cannot be changed. 2D arrays can store either primitive data or object reference data.
      • Exclusion statement: Nonrectangular 2D array objects are outside the scope of the AP Computer Science A course and exam.
    • 4.11.A.2 When a 2D array is created using the keyword new, all of its elements are initialized to the default values for the element data type. The default value for int is 0, for double is 0.0, for boolean is false, and for a reference type is null.
    • 4.11.A.3 The initializer list used to create and initialize a 2D array consists of initializer lists that represent 1D arrays; for example, int[][] arr2D = { {1, 2, 3}, {4, 5, 6} };.
    • 4.11.A.4 The square brackets [row][col] are used to access and modify an element in a 2D array. For the purposes of the exam, when accessing the element at arr[first][second], the first index is used for rows, the second index is used for columns.
    • 4.11.A.5 A single array that is a row of a 2D array can be accessed using the 2D array name and a single set of square brackets containing the row index.
    • 4.11.A.6 The number of rows contained in a 2D array can be accessed through the length attribute. The valid row index values for a 2D array are 0 through one less than the number of rows or the length of the array, inclusive. The number of columns contained in a 2D array can be accessed through the length attribute of one of the rows. The valid column index values for a 2D array are 0 through one less than the number of columns or the length of any given row of the array, inclusive. For example, given a 2D array named values, the number of rows is values.length and the number of columns is values[0].length. Using an index value outside of these ranges will result in an ArrayIndexOutOfBoundsException.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    A 2D array 二维数组 is a grid (rows and columns) – an array of arrays:

    עברית

    מערכת 2D היא רשת (שורות ועמודות) – מערכת של מערכות:

    מערכת דו-ממדית (טבלה) עם אינדקסים לשורה ועמודה
    מערכת דו-ממדית (טבלה) עם אינדקסים לשורה ועמודה
    int[][] grid = new int[3][4];   // 3 rows, 4 columns
    grid[r][c] = 7;                 // row r, column c
    int rows = grid.length;         // 3
    int cols = grid[0].length;      // 4
    
    Explore · ⁨חקור⁩

    Index a 2D array by row and column · ⁨מדד מערך דו-ממדי 2 לפי שורה ועמודה⁩

    A 2D array is a grid addressed by [row][col]. Move the indices and watch which cell they select — row first, then column, both counting from 0. · ⁨מערך D-2 הוא רשת המיועדת ב[row][col]. הזז את האינדקסים וצפה איזה תא הם בוחרים — שורה קודם, ואז עמודה, שניהם סופרים מ0.⁩

    4.12

    Walking Through a Grid · ⁨הליכה דרך רשת⁩

    Syllabus · ⁨סיילבוס⁩
    Learning ObjectiveEssential Knowledge

    4.12.A
    Develop code used to traverse the elements in a 2D array and determine the result of these traversals.

    • 4.12.A.1 Nested iteration statements are used to traverse and access all or an ordered sequence of elements in a 2D array. Since 2D arrays are stored as arrays of arrays, the way 2D arrays are traversed using for loops and enhanced for loops is similar to 1D array objects. Nested iteration statements can be written to traverse the 2D array in row-major order, column-major order, or a uniquely defined order. Row-major order refers to an ordering of 2D array elements where traversal occurs across each row, whereas column-major order traversal occurs down each column.
    • 4.12.A.2 The outer loop of a nested enhanced for loop used to traverse a 2D array traverses the rows. Therefore, the enhanced for loop variable must be the type of each row, which is a 1D array. The inner loop traverses a single row. Therefore, the inner enhanced for loop variable must be the same type as the elements stored in the 1D array. Assigning a new value to the enhanced for loop variable does not change the value stored in the array.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English
    Traversing a 2-D array

    Visit every cell with nested loops – the outer over rows, the inner over columns (row-major order 行主序):

    עברית
    עבודה על מערך 2-D

    ביקור בכל תא באמצעות לולאות פנימיות – החיצונית על שורות, הפנימית על עמודות (סדר טור-עיקרי):

    for (int r = 0; r < grid.length; r++)
        for (int c = 0; c < grid[0].length; c++)
            System.out.print(grid[r][c]);
    
    4.13

    Standard 2D Array Algorithms · ⁨אלגוריתמי מערך דו-ממדי ⟨2⟩ סטנדרטיים⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.13.A: Develop code for standard and original algorithms for a particular context or specification that involves 2D arrays and determine the result of these algorithms.

    • 4.13.A.1 There are standard algorithms that utilize 2D array traversals to:
      • determine a minimum or maximum value of all the elements or for a designated row, column, or other subsection
      • compute a sum or average of all the elements or for a designated row, column, or other subsection
      • determine if at least one element has a particular property in the entire 2D array or for a designated row, column, or other subsection
      • determine if all elements of the 2D array or a designated row, column, or other subsection have a particular property
      • determine the number of elements in the 2D array or in a designated row, column, or other subsection having a particular property
      • access all consecutive pairs of elements
      • determine the presence or absence of duplicate elements in the 2D array or in a designated row, column, or other subsection
      • shift or rotate elements in a row left or right or in a column up or down
      • reverse the order of the elements in a row or column
    עברית

    מטרת למידה 4.13.A: פיתוח קוד לאלגוריתמים סטנדרטיים וחדשניים בהקשר או מפרט מסוים המשתמש במערכים בעל-ממד 2 וקביעת תוצאת האלגוריתמים הללו.

    • 4.13.A.1 קיימים אלגוריתמים סטנדרטיים המשתמשים במעבר (traversal) על מערכים בעל-ממד 2 כדי:
      • לקבוע ערך מינימום או מקסימום של כל האלמנטים או עבור שורה, עמודה או תת-אזור מוגדר אחר
      • לחשב סכום או ממוצע של כל האלמנטים או עבור שורה, עמודה או תת-אזור מוגדר אחר
      • לקבוע אם לפחות אלמנט אחד בעל מאפיין מסוים בכל המערכת בעל-ממד 2 או בשורה, עמודה או תת-חלק אחר ממוינת
      • לקבוע אם כל האלמנטים במערכת בעל-ממד 2 או בשורה, עמודה או תת-חלק אחר ממוינים הם בעלי מאפיין מסוים
      • לקבוע את מספר האלמנטים במערכת בעל-ממד 2 או בשורה, עמודה או תת-חלק אחר ממוינים המצוינים במאפיין מסוים
      • לגשת לכל הזוגות הרצופים של אלמנטים
      • לקבוע את נוכחותם או היעדרם של אלמנטים כפולים במערכת בעל-ממד 2 או בשורה, עמודה או תת-חלק אחר ממוינים
      • להזיז או לסובב אלמנטים בשורה שמאלה או ימינה או בעמודה למעלה או למטה
      • להפוך את סדר האלמנטים בשורה או בעמודה

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English

    Typical grid tasks: sum a row or column, find the max in the grid, count matching cells, or sum a diagonal (where r == c). Each is a nested traversal with a running result.

    עברית

    משימות רשת נפוצות: חיבור שורה או עמודה, מציאת הערך המקסימום ברשת, ספירת תאים תואמים, או חיבור אלכסון (כאן r == c). כל אחת מהן היא טרברס פנימי עם תוצאה מצטברת.

    4.14

    Finding a Value: Linear and Binary Search · ⁨מציאת ערך: חיפוש ליני ואינסולטיבי⁩

    Syllabus · ⁨סיילבוס⁩
    Learning ObjectiveEssential Knowledge

    4.14.A
    Develop code used for linear search algorithms to search for specific information in a collection and determine the results of executing a search.

    • 4.14.A.1 Linear search algorithms are standard algorithms that check each element in order until the desired value is found or all elements in the array or ArrayList have been checked. Linear search algorithms can begin the search process from either end of the array or ArrayList.
    • 4.14.A.2 When applying linear search algorithms to 2D arrays, each row must be accessed then linear search applied to each row of the 2D array.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English
    Binary search: halve and conquer
    • Linear search 线性搜索 checks each element in turn – works on any list, taking up to $n$ steps.
    • Binary search 二分搜索 works only on a sorted list: check the middle, then discard the half that cannot contain the target, repeating. It takes about $\log_2 n$ steps – far faster on large data.

    Exam skill: binary search requires sorted data; know how many comparisons it makes and how lo, hi, mid update.

    Worked example. Search for target = 40 in the sorted array {3, 9, 14, 23, 31, 42, 55} (indices 0–6). Start lo=0, hi=6:

    • mid = (0+6)/2 = 3, a[3]=23 < 40, so lo = 4;
    • mid = (4+6)/2 = 5, a[5]=42 > 40, so hi = 4;
    • mid = (4+4)/2 = 4, a[4]=31 < 40, so lo = 5;
    • now lo (5) > hi (4), so the loop ends – 40 is not present.

    Each step halved the range, so even this miss took only three comparisons.

    עברית
    חיפוש בינארי: חלוקה לשתיים וכיבוש
    • חיפוש ליני בודק כל אלמנט בסדר – עובד על כל רשימה, לוקח עד $n$ צעדים.
    • חיפוש אינסולטיבי עובד רק על רשימה מוסדרת: בודק את האמצע, ולאחר מכן מתעלם מחצית שאינה יכולה להכיל את המטרה, ומשחזר. לוקח כ-$\log_2 n$ צעדים – הרבה מהיר יותר על נתונים גדולים.
    חיפוש אינסולטיבי חוצה את הטווח במחצית בכל צעד
    חיפוש אינסולטיבי חוצה את הטווח במחצית בכל צעד
    חיפוש ליני בודק כל אלמנט בסדר עד שמצוי המטרה
    חיפוש ליני בודק כל אלמנט בסדר עד שמצוי המטרה
    int lo = 0, hi = a.length - 1;
    while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (a[mid] == target) return mid;
        else if (a[mid] < target) lo = mid + 1;
        else hi = mid - 1;
    }
    

    מיומנות לבחינה: חיפוש אינסולטיבי דורש נתונים מסודרים; יש לדעת כמה השוואות הוא מבצע וכיצב lo, hi, mid מתעדכנים.

    דוגמה מפורטת. חפש את target = 40 ברשימה המוסדרת {3, 9, 14, 23, 31, 42, 55} (אינדקסים 0–6). התחל ב-lo=0, hi=6:

    • mid = (0+6)/2 = 3, a[3]=23 < 40, ולכן lo = 4;
    • mid = (4+6)/2 = 5, a[5]=42 > 40, ולכן hi = 4;
    • mid = (4+4)/2 = 4, a[4]=31 < 40, ולכן lo = 5;
    • עכשיו lo (5) > hi (4), ולכן הלולאה נגמרת – 40 לא קיים.

    בכל צעד הטווח הועבר במחצית, ולכן גם כשל זה לקח רק שלוש השוואות.

    Explore · ⁨חקור⁩

    Compare linear and binary search · ⁨השוו חיפוש ליניארי לחיפוש בינארי⁩

    Linear search checks every element in turn; binary search halves a sorted list each step. Watch binary search reach the target in far fewer comparisons. · ⁨חיפוש ליניארי בודק כל אלמנט בתורו; חיפוש בינארי מחצית רשימה מוערכת בכל צעד. צפו כיצד החיפוש הבינארי מגיע למטרה במספר השוואות פחות משמעותי.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Linear search/ˈlɪnɪə sɜːtʃ/ חיפוש ליניארי
    Binary search/ˈbaɪnəri sɜːtʃ/ חיפוש ביינארי
    Selection sort/sɪˈlekʃn sɔːt/ מיון בחירה
    4.15

    Putting Data in Order: Selection and Insertion Sort · ⁨סידור נתונים: מיון בחירה ומיון הכנסה⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.15.A: Determine the result of executing each step of sorting algorithms to sort the elements of a collection.

    • 4.15.A.1 Selection sort and insertion sort are iterative sorting algorithms that can be used to sort elements in an array or ArrayList.
    • 4.15.A.2 Selection sort repeatedly selects the smallest (or largest) element from the unsorted portion of the list and swaps it into its correct (and final) position in the sorted portion of the list.
    • 4.15.A.3 Insertion sort inserts an element from the unsorted portion of a list into its correct (but not necessarily final) position in the sorted portion of the list by shifting elements of the sorted portion to make room for the new element.
    עברית

    מטרות למידה 4.15.A: לקבוע את התוצאה של ביצוע כל שלב באלגוריתמי מיון כדי למיין את אלמנטיה של אוסף.

    • 4.15.A.1 מיון בחירה ומיון הכנסה הם אלגוריתמי מיון איטרטיביים (איטרטיביים) שניתן להשתמש בהם למיין אלמנטים במערך או ArrayList.
    • 4.15.A.2 מיון בחירה בוחר באופן חוזר את האלמנט הקטן ביותר (או הגדול ביותר) מהחלק הלא-מומין של הרשימה ומחליף אותו למיקומו הנכון (וגם הסופי) בחלק המומין של הרשימה.
    • 4.15.A.3 מיון הכנסה מכניס אלמנט מהחלק הלא-מומין של רשימה למיקומו הנכון (אולם לא נרחב הסופי) בחלק המומין של הרשימה על ידי הזזת אלמנטים מהחלק המומין כדי לפנות מקום לאלמנט החדש.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English
    Insertion sort
    Bubble sort, pass by pass
    • Selection sort 选择排序 repeatedly finds the smallest remaining element and swaps it into place.
    • Insertion sort 插入排序 grows a sorted front, inserting each new element where it belongs.

    Both are simple and take about $n^2$ steps on average – fine for small arrays. Be able to trace the array after each pass.

    עברית
    מיון הכנסה
    מיון בועות, מעבר אחר מעבר
    • מיון בחירה מוצא שוב ושוב את הקטן ביותר שנותר ומחליף אותו למקומו.
    • מיון הכנסה בונה חזית מסודרת, ומכניס כל אלמנט חדש למיקומו הנכון.
    מיון הכנסה, המעביר כל מפתח למקומו מעבר לעבר
    מיון הכנסה, המעביר כל מפתח למקומו מעבר לעבר

    שניהם פשוטים ודורשים כ-$n^2$ צעדים בממוצע – מתאימים לאריי קטנים. יש להצליח לעקוב אחרי האריי לאחר כל מעבר.

    Explore · ⁨חקור⁩

    Watch a sorting algorithm order a list · ⁨צפו אלגוריתם מיון מסדר רשימה⁩

    A sort rearranges elements into order. Step through selection/insertion sort to see the sorted region grow one element at a time. · ⁨מיון מסדר מחדש אלמנטים לסדר. צעדו לאורך מיון בחירה/הכנסה כדי לראות את האזור הממוין גדל אלמנט אחד בכל פעם.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Insertion sort/ɪnˈsɜːʃn sɔːt/ מיון הכנסה
    4.16

    Methods That Call Themselves: Recursion · ⁨שיטות הקוראות את עצמן: רקורסיה⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.16.A: Determine the result of calling recursive methods.

    • 4.16.A.1 A recursive method is a method that calls itself. Recursive methods contain at least one base case, which halts the recursion, and at least one recursive call. Recursion is another form of repetition.
    • 4.16.A.2 Each recursive call has its own set of local variables, including the parameters. Parameter values capture the progress of a recursive process, much like loop control variable values capture the progress of a loop.
    • 4.16.A.3 Any recursive solution can be replicated through the use of an iterative approach and vice versa.
      • Exclusion statement: Writing recursive code is outside the scope of the AP Computer Science A course and exam.
    עברית

    מטרות למידה 4.16.A: לקבוע את התוצאה של קריאת מתודות רקורסיביות.

    • 4.16.A.1 מתודה רקורסיבית היא מתודה הנקראת לעצמה. מתודות רקורסיביות מכילות לפחות מקרה בסיס אחד, המעצור את הרקורסיה, ולפחות קריאה רקורסיבית אחת. רקורסיה היא צורה אחרת של חזרה.
    • 4.16.A.2 לכל קריאה רקורסיבית ישנו ערך עצמי של משתנים מקומיים, כולל הפרמטרים. ערכי הפרמטרים תופסים את התקדמות תהליך רקורסיבי, בדומה לכך שערכי משתנה בקרת מחזור תופסים את התקדמות מחזור.
    • 4.16.A.3 כל פתרון רקורסיבי ניתן לשחזר באמצעות גישת איטרציה ולהפך.
      • הצהרת יציאה: כתיבת קוד רקורסיבי אינה בטווח הלימודים של קורס ובחינת AP Computer Science A.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English
    Recursion & the call stack

    Recursion 递归 is a method that calls itself on a smaller input. It needs a base case 基本情况 that stops the calls, and a recursive case that moves toward the base:

    Without a reachable base case, recursion never stops (a stack overflow).

    Recursion and iteration are interchangeable. Any recursive solution can be rewritten with a loop (an iterative approach), and any loop can be rewritten with recursion - they solve the same problems. The factorial above is identical in effect to an iterative version:

    So the choice is about clarity, not capability: recursion reads naturally for problems with a self-similar structure (trees, merge sort), while iteration avoids the memory cost of stacking a call frame per step. The exam may ask you to convert one into the other.

    עברית
    רקורסיה ותור הפקודות

    רקורסיה היא שיטה הקוראת את עצמה על קלט קטן יותר. היא דורשת מקרה בסיס שמפסיק את ההתקשרויות, ומקרה רקורסיבי שמקרב אותן למקרה הבסיס:

    public static int factorial(int n) {
        if (n <= 1) return 1;          // base case
        return n * factorial(n - 1);   // recursive case
    }
    

    ללא מקרה בסיס הניתן להישג, הרקורסיה לעולם אינה נפסקת (שפל עומס).

    רקורסיה ואיטרציה הם חלופיים. כל פתרון רקורסיבי ניתן לשינוי באמצעות לולאה (גישה איטרטיבית), וכל לולאה ניתנת לשינוי ברקורסיה – הן פותרות את אותם בעיות. ה-factorial למעלה זהה בהשפעה לגרסה איטרטיבית:

    public static int factorial(int n) {
        int result = 1;
        for (int i = 2; i <= n; i++) result *= i;   // same answer, no self-call
        return result;
    }
    

    לכן הבחירה היא בנוגע ל-בהירות, לא ליכולת: רקורסיה נקראת טבעית לבעיות עם מבנה דומה-לעצמו (עצים, מיזוג), בעוד שאיטרציה נמנעת מהעלות הזיכרון של ערימת מסגרת קריאה בכל צעד. במבחן ייתכן שישאלו להמיר אחת לשנייה.

    Explore · ⁨חקור⁩

    Unfold a recursive call · ⁨פרקו קריאה רקורסיבית⁩

    A recursive method calls itself on a smaller input until it hits a base case, then the results fold back up. Step through to watch the calls stack and unwind. · ⁨מתודה רקורסיבית קוראת לעצמה על קלט קטן יותר עד שהיא מגיעה למקרה בסיס, ולאחר מכן התוצאות מתקפלות חזרה. צעדו כדי לצפות בערימת הקריאות ובביטולן.⁩

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Recursion/rɪˈkɜːʃn/ רקורסיה
    base case/beɪs keɪs/ מקרה בסיסי
    4.17

    Recursive Search and Merge Sort · ⁨חיפוש רקורסיבי ומיון מיזוג⁩

    Syllabus · ⁨סיילבוס⁩
    English

    Learning Objective 4.17.A: Determine the result of executing recursive algorithms that use strings or collections.

    • 4.17.A.1 Recursion can be used to traverse String objects, arrays, and ArrayList objects.

    Learning Objective 4.17.B: Determine the result of each iteration of a binary search algorithm used to search for information in a collection.

    • 4.17.B.1 Data must be in sorted order to use the binary search algorithm. Binary search starts at the middle of a sorted array or ArrayList and eliminates half of the array or ArrayList in each recursive call until the desired value is found or all elements have been eliminated.
    • 4.17.B.2 Binary search is typically more efficient than linear search.
      • Exclusion statement: Search algorithms other than linear and binary search are outside the scope of the AP Computer Science A course and exam.
    • 4.17.B.3 The binary search algorithm can be written either iteratively or recursively.

    Learning Objective 4.17.C: Determine the result of each iteration of the merge sort algorithm when used to sort a collection.

    • 4.17.C.1 Merge sort is a recursive sorting algorithm that can be used to sort elements in an array or ArrayList.
      • Exclusion statement: Sorting algorithms other than selection, insertion, and merge sort are outside the scope of the AP Computer Science A course and exam.
    • 4.17.C.2 Merge sort repeatedly divides an array into smaller subarrays until each subarray is one element and then recursively merges the sorted subarrays back together in sorted order to form the final sorted array.
    עברית

    מטרות למידה 4.17.A: לקבוע את התוצאה של ביצוע אלגוריתמים רקורסיביים המשתמשים במילים או באוספים.

    • 4.17.A.1 ניתן להשתמש ברקורסיה כדי לעבור על String אובייקטים, מערכים וArrayList אובייקטים.

    מטרות למידה 4.17.B: לקבוע את התוצאה של כל איטרציה של אלגוריתם חיפוש בינארי המשמש לחיפוש מידע באוסף.

    • 4.17.B.1 נתונים חייבים להיות במיון כדי להשתמש באלגוריתם חיפוש בינארי. חיפוש בינארי מתחיל באמצע מערך ממוין או ArrayList ומסיר חצי מהמערך או ArrayList בכל קריאה רקורסיבית עד שמצאים את הערך הרצוי או שנכלו כל האלמנטים.
    • 4.17.B.2 חיפוש בינארי הוא בדרך כלל יעיל יותר מחיפוש ליניארי.
      • הצהרת יציאה: אלגוריתמי חיפוש אחרים מחיפוש ליניארי ובינארי אינם בטווח הלימודים של קורס ובחינת AP Computer Science A.
    • 4.17.B.3 אלגוריתם החיפוש הבינארי יכול להיות מוגדר באופן איטרטיבי או רקורסיבי.

    מטרת הלמידה 4.17.C: לקבוע את התוצאה של כל איטרציה של אלגוריתם ה-Merge Sort בעת מיון קבוצת נתונים.

    • 4.17.C.1 Mergesort הוא אלגוריתם מיון רקורסיבי שיכול לשמש למיון אלמנטים במערכת או במערכת בעל-ממד ArrayList.
      • הערה על היקף: אלגוריתמי מיון אחרים מאלו שנקראו (Selection Sort, Insertion Sort, Merge Sort) אינם נכללים בקורס ובמבחן AP Computer Science A.
    • 4.17.C.2 Merge Sort מחלק באופן חוזר מחדש את המערך לזרים קטנים יותר עד שכל זר מכיל אלמנט אחד בלבד, ולאחר מכן מאחד רקורסיבית את הזרים הממוינים יחד בסדר ממוין כדי ליצור את המערך הסופי הממוין.

    Source: College Board AP Course and Exam Description · ⁨מקור: תיאור הקורס והמבחן של College Board AP⁩

    English
    Merge sort: split, then merge

    Recursion powers efficient algorithms. Binary search can be written recursively (search the correct half). Merge sort 归并排序 splits the array in half, sorts each half recursively, then merges the two sorted halves – taking about $n\log_2 n$ steps, much faster than selection or insertion sort on large data.

    Worked example. Trace factorial(4). Each call defers to a smaller one: factorial(4) = 4 * factorial(3) = 4 * 3 * factorial(2) = 4 * 3 * 2 * factorial(1). factorial(1) hits the base case and returns 1, so the calls unwind inward: 2 * 1 = 2, then 3 * 2 = 6, then 4 * 6 = 24. Writing each call above its returned value is the reliable way to trace recursion.

    Exam skill: trace a recursive method by writing out each call and its return value, and know that merge sort's efficiency ($n\log n$) beats the $n^2$ simple sorts.

    עברית
    מיזוג-סידור: פיצול, ואז מיזוג

    רקורסיה מניעה אלגוריתמים יעילים. חיפוש בינארי ניתן לכתיבה רקורסיבית (חיפוש בחצי הנכון). מיזוג מחלק את האריי לחציים, ממין כל חצי רקורסיבית, ולאחר מכן ממזג את שני החצאים הממוינים – תוך כ-$n\log_2 n$ צעדים, מהיר משמעותית מאיחוי או מיון הכנסה על נתונים גדולים.

    מיזוג מחלק את האריי לאלמנטים בודדים, ולאחר מכן ממזג חצאים ממוינים חזרה כלפי מעלה
    מיזוג מחלק את האריי לאלמנטים בודדים, ולאחר מכן ממזג חצאים ממוינים חזרה כלפי מעלה

    דוגמה פעילה. עקוב אחרי factorial(4). כל קריאה מעוכבת לקריאה קטנה יותר: factorial(4) = 4 * factorial(3) = 4 * 3 * factorial(2) = 4 * 3 * 2 * factorial(1). factorial(1) פוגש את המקרה הבסיס ומחזיר 1, ולכן הקריאות מתפרקות פנימה: 2 * 1 = 2, ולאחר מכן 3 * 2 = 6, ולאחר מכן 4 * 6 = 24. כתיבת כל קריאה מעל הערך שהוחזר היא הדרך האמינה לעקוב אחר רקורסיה.

    מיומנות במבחן: עקוב אחר שיטה רקורסיבית על ידי כתיבת כל קריאה וערך ההחזרה שלה, ודע כי יעילות המיזוג ($n\log n$) עולה על סיווג פשוטים כמו $n^2$.

    Vocabulary · ⁨מילון מונחים⁩ Train · ⁨אימון⁩
    English עברית
    Merge sort/mɜːdʒ sɔːt/ מיון מיזוג
    4.17

    Exam tips · ⁨טיפים לבחינות⁩

    English
    • Weigh both benefits and harms of collecting data — this unit is tested through short written justification, not code.
    • Protect personally identifiable information (PII) and explain privacy and security risks in context.
    • Name real harms: data breaches, surveillance, and algorithmic bias from unrepresentative data.
    • Respect intellectual property and licensing when you reuse code or data.
    • Give a specific, reasoned answer — a vague "it could be bad" earns no marks.
    עברית
    • שקול את היתרונות והנזקים של איסוף נתונים – יחידה זו נבדקת דרך נימוק כתוב קצר, לא קוד.
    • הגן על מידע זיהוי אישי (PII) והסבר סיכוני פרטיות ואבטחה בהקשר.
    • ציין נזקים אמיתיים: הפרות נתונים, ניטור, והטיה אלגוריתמית מהנתונים שאינם מייצגים.
    • כבד ברוח הרוחנית וברישויים כאשר אתה מוסיף קוד או נתונים.
    • תן תשובה ספציפית ומנומקת – "ייתכן שזה רע" הוא תשובה מטושטשת שאינה זוכה לנקודות.

Log in or create account · ⁨היכנס או צור חשבון⁩

IGCSE, A-Level & AP