1/112
Fall Review of AP Computer Science
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Class
A blueprint for creating objects that defines a set of attributes and methods.
Object
An instance of a class that contains actual values.
Constructor
A special method used to initialize objects in a class.
Null Reference
Indicates that a reference variable does not point to any object.
Formal Parameters
The variables defined by a method or constructor that receive values.
Actual Parameters
The actual values passed into the constructor or method when invoked.
Overloaded Constructor
Constructors with the same name but different parameter lists.
Void Method
A method that does not return any value.
Immutable String
A String whose value cannot be changed once created.
Autoboxing
Automatic conversion from a primitive type to its corresponding wrapper class.
Integer.MIN_VALUE
This represents the smallest value an integer can have.
Math.pow
A method that raises a base to the power of an exponent.
Math.sqrt
A method that returns the square root of a number.
Exception
An error condition that alters the normal flow of program execution.
String Concatenation
The process of joining two or more strings together.
Random Integer Generation
A method to produce a random integer value within a specified range.
private
A keyword used to restrict access to a variable, allowing it to be accessed only within the declaring class.
public instance variables
Should generally be marked private for encapsulation (since they are not public).
this keyword
Refers to the current object, allowing access to its instance variables or methods.
accessor method
A type of method typically used to provide access to private instance variables.
static keyword
Used to define a class-level shared variable.
default access modifier
It is accessible within the same package (Private-Package).
Comments(Javadoc)
Documenting API functionality typically uses this type of comment (/** */).
constructor naming
constructors must have the same name as the class.
default no-argument constructor
Provided by Java if no constructor is specified for a class.
single-line comment in Java
An example would be: // This is a single-line comment.
mutable objects
Should be copied before being assigned to instance variables to avoid unintended modifications.
static variable purpose
Associates the variable with the class rather than any specific instance.
accessor vs mutator methods
Accessor methods retrieve values, while mutator methods modify values.
method header for getName
public String getName()
toString method behavior
If not overridden, it returns the object's class name and hash code.
static method access
a static method cannot access instance variables of the class.
local vs instance variable conflict
The local variable is used, shadowing the instance variable.
constructor header for Student
public Student(String name, int age)
data encapsulation
Restricting access to an object's internal state and exposing controlled access through methods.
this keyword conflict resolution
It specifies that the instance variable should be used (this.variableName).
accessor method for private id
public int getId() { return id; }
ethical considerations in class design
Ensuring data security and privacy by implementing proper access controls and avoiding data leaks.
Java class Book example
public class Book { private String title; private String author; public Book(String title, String author) { this.title = title; this.author = author; } }
output of Counter class code
Count: 1
error in getPrice method
Should return an int; to fix: public int getPrice() { return price; }
toString method for Book class
public String toString() { return "Title: " + title + ", Author: " + author; }
output of StaticExample class
2, indicating how many instances of the class were created.
While Loop
A control flow statement that allows code to be executed repeatedly based on a given boolean condition.
For Loop
A control flow statement that allows code to be executed a specific number of times, with a defined initialization, condition, and increment.
Increment Section
The part of a for loop that specifies how the loop control variable should change after each iteration.
Boolean Condition
An expression evaluated to true or false to control the flow of loops.
Off by One Error
A common programming error where a loop iterates one too many or one too few times, often related to the starting or ending conditions.
Nested Loop
A loop inside another loop, where the inner loop executes completely for each iteration of the outer loop.
Return Statement in a Loop
A statement used to exit a function, which also results in exiting any loop that encloses it.
String Traversal Algorithm
An algorithm that goes through each character of a string to perform actions like counting vowels.
Maximum Value in Array
The largest number found in a given array of integers.
Reverse a String
An algorithm that creates a new string consisting of characters in the opposite order of their original arrangement.
Relational Operator
An operator that compares two values and returns a boolean result.
Boolean Expression
An expression that evaluates to either true or false.
Short-Circuited Evaluation
A method of evaluating logical expressions that stops as soon as the result is determined.
&& Operator
The logical AND operator that returns true only if both operands are true.
|| Operator
The logical OR operator that returns true if at least one of the operands is true.
Null Reference
A reference that does not point to any object.
De Morgan’s Laws
A pair of transformation rules that relate conjunctions and disjunctions of propositions.
If-Else Statement
A control structure that executes different blocks of code based on a boolean condition.
Boolean Negation
The operation of inverting the truth value of a boolean expression.
Truth Table
A table that shows all possible truth values for a logical expression.
Default value of uninitialized int in Java
value of uninitialized int = 0
Primitive type for true/false values
Boolean
Declaration for a String variable named 'name'
String name;
Primitive type for decimal numbers
double
Result of 10 / 4 in integer division
2
Declaration for a boolean variable named 'isActive'
boolean isActive;
What happens when an int is divided by a double?
It auto casts to double.
Default value of a boolean in Java
false or 0
Primitive types on the AP Test
int, double, boolean
Result of 3.0 / 2 in Java
1.5
Result of true || false
the result will be True (or/and prob)
Result of true && false
The result will be False (and/or prob)
Evaluation of !(x == 5) when x = 5
This expression evaluates to false because the equality check "x == 5" is true, and the logical NOT operator negates that result.
Boolean expression for x not between 10 and 20 inclusive
!(x >= 10 && x <= 20)
Result of !(a > 5 || b < 3) when a = 6 and b = 2
6 is less than 5 and 2 is less than 3 the negation function will make it false
Simplification of !(x && y) using De Morgan's Law
!x || !y
Simplification of !(a || b) using De Morgan's Law
!a && !b
Simplification of !(x > 5 && y < 10) using De Morgan's Law
!x || y >= 10
Output of System.out.println(a / 2 * 2) when a = 7
6
Issue with 'double value = 3.7; int num = value;'
Cannot assign a double to an int without explicit casting.
Code to declare int variable 8, cast to double and print
int num = 8; double result = (double) num; System.out.println(result);
Boolean expression for x divisible by 3 but not by 5
x % 3 == 0 && x % 5 != 0
Output when x = 5 and x > 3 && x < 10
this will be True since 5 is bigger than 3 and smaller than 10
Result of ! (10 > 5 || 2 < 3)
even though 10 is bigger that 5 and 2 is less than 3 negation will make it False
Result when x = 8, y = 6 for x == 8 || y != 5 && y == 6
The result is true because x equals 8.
Default value of uninitialized int variable in Java
The default value of an uninitialized int variable in Java is 0.
Primitive type for true/false values
Boolean
Valid declaration for a String variable
String name;
Primitive type for storing decimal numbers
double
Result of 10 / 4 in integer division
2
Declaration of a boolean variable
boolean simesterDone;
Result when dividing an int by a double
It auto casts to double.
Default value of a boolean in Java
false (Boolean value)
Primitive types on the AP Test
int, double, boolean
Result of 3.0 / 2 in Java
1.5
Result of true || false
will produce true (|| statement)
Result of true && false
will produce False (&& statement)