AP Comp Sci A Meeting
4/20/2023
The Basics
Identifiers
Built-in/Primitive Types
Storage of numbers
Miscellaneous Note #1
Number representation
Final Variables
Arithmetic Operators
Operator | Meaning | Example |
+ | Addition | 3 + x |
- | Subtraction | p – q |
* | Multiplication | 6 * i |
/ | Division | 10 / 4�//returns 2 |
% | Mod (remainder) | 11 % 8�//returns 3 |
Arithmetic Operators Notes
Relational Operators
Operator | Meaning | Example |
== | Equal to | if (x == 100) |
!= | Not equal to | if (age != 21) |
> | Greater than | if (salary > 30000) |
< | Less than | if (grade < 65) |
>= | Greater than or equal to | if (age >= 16) |
<= | Less than or equal to | if (height <= 6) |
Relational Operators Notes
Logical Operators
Operator | Meaning | Example |
! | NOT | if (!found) |
&& | AND | if (x < 3 && y > 4) |
|| | OR | if (age < 2 || height < 4) |
Logical Operators Example
Another example
Assignment Operators
Operator | Example | Meaning |
= | x = 2 | Simple assignment |
+= | x += 4 | x = x + 4 |
-= | y -= 6 | y = y – 6 |
*= | p *= 5 | p = p * 5 |
/= | n /= 10 | n = n / 10 |
%= | n %= 10 | n = n % 10 |
++ | k++ | k = k + 1 |
-- | i-- | i = i - 1 |
Operator Precedence
Control Structures
if Statement
if (boolean expression)
{
statements
}
//statements will be executed if boolean expression is true
if…else Statement
if (boolean expression)
{
statements � //will be executed if boolean expression is true
}
else
{
statements
//will be executed if boolean expression is false
}
if…else if
if (grade.equals(“A”))� System.out.println(“Excellent”);�else if(grade.equals(“B”))� System.out.println(“Good”);�else if(grade.equals(“C”))� System.out.println(“Poor”);�else� System.out.println(“Invalid”);
Other if Notes
While vs. For loops
While loops
For loops
For loop vs. for-each loop
For loop
For-each loop
For loop vs. for-each loop
For loop
For-each loop
While loop example
For loop example
Objects, Classes, and Inheritance
Method Headers
Types of Methods
Static methods in Driver class
Method Overloading
Inheritance
Implementing Subclasses
Inheriting Instance Methods/Variables
Method Overriding and super
Rules for Subclasses
Declaring Subclass Objects
Polymorphism
Type Compatibility
Abstract Class
Notes about abstract classes
Interfaces
Interface vs. Abstract Class
Lists and Arrays
1-D Arrays
1-D Array Initialization
1-D initializing values
Array Length
Traversing an Array
What to do with arrays
Counting & Printing
Summing Values
Summing Values
Summing Values
Swapping values
Min and Max
Arrays vs. ArrayList
Arrays
ArrayList
String[] arr = new String[10];�…�//insert Strings into array�…�for(int i=0; i<arr.length; i++)�{� System.out.println(arr[i]);�}�
ArrayList<String> arrList = new ArrayList<String>();�…�//insert Strings into ArrayList�…�for(int i=0; i<arr.size(); i++)�{� System.out.println (arrList.get(i));�}
Arrays vs. ArrayList
Arrays
ArrayList
String[] arr = new String[10];�…�//insert Strings into array�…�for(String x : arr)�{� System.out.println(x);�}�
ArrayList<String> arrList = new ArrayList<String>();�…�//insert Strings into ArrayList�…�for(String x : arrList)�{� System.out.println(x);�}
Arrays vs. ArrayList
Arrays
ArrayList
Fixed length, set when it is created��Must keep track of last slot if array is not full��Must write code to shift elements if you want to insert or delete
Shrinks and grows as needed���Last slot is always arrList.size()-1��Insert with just�arrList.add(object)�Delete with just arrList.remove(objectIndex) or arrList.remove(object)
Insert and Delete
ArrayList Question
removeAll
removeAll
2-D Arrays
2-D Array as a table
int numRows = 3;
int numCols = 3;
String[][] table = � new String[numRows][numCols];
table[2][0] = “x”;
Sorting and Searching
Selection Sort Algorithm (ascending)
“Search and swap” algorithm:
Selection Sort Example(ascending)
Selection Sort Notes
Insertion Sort Algorithm (ascending)
Insertion Sort Algorithm (ascending)
Insertion Sort Question
Insertion Sort Notes
Merge Sort Algorithm
Merge Sort Example
Merge Sort Example
Merge Sort Notes
Merge Sort Question
Binary Search
Recursive
How many executions?
Kahoot
Board Application Information
Attendance Form (Programming Club)