Essential knowledge

This page contains the essential facts you should have learned in AP CSA. It is in some ways distilled and in some ways expanded from the “essential knowledge” items from the College Board’s AP CSA Course and Exam Description.

It is condensed insofar as I was able to combine topics that are spread out over several units in the curriculum now since we’ve now covered them all. But it is expanded in that I tried to add a bit of nuance or even just clarity to the individual items compared to how the College Board wrote them.

Data types

Variables

Expressions

Arithmetic expressions

Boolean expressions

Logical operators

Equality operators

Relational operators

Assignment operators

Methods

Method structure

Method calls

Naming methods in method calls

Control constructs

Conditional control constructs

Looping control constructs

Arrays

2d arrays

Classes

static members

Instance variables

Constructors

Methods in classes

Access modifiers

Encapsulation

toString

this

Comments

Invariants

Overloading

Inheritance

Constructors in inheritance hierarchies

Inherited methods

Types and inheritance

Built in classes

Strings

The System class

The Math class

ArrayLists

Wrapper classes

Algorithms

Recursion

Stuff the College Board just had to get off their chest

1 The AP curriculum does not touch on this but Casting a double value outside the range that can be represented by an int results in either Integer.MAX_VALUE or Integer.MIN_VALUE.

2 One way to remember the relative precedence is to note that if you think of booleans as a kind of numbers with false analogous to 0 and true analogous to 1, then ! is equivalent to a single negation as in -x, which flips the sign of its value, && is analogous to multiplication since true && x is x for all boolean x just like 1 * x is x for all numeric x and || is like addition since false || x is x for all boolean x, just like 0 + x is x for all numeric x.)

3 This can be useful when the second expression would not be safe to evaluate in some circumstances. For instance: s.length() >= 3 && s.substring(0, 3).equals(“abc”) evaluates to false if the string is less than three characters long without trying to extract a substring which would throw an exception if the string is not that long.

4 The equals method is not an operator; just a method that returns a boolean.

5 The AP curriculum does not cover it but these operators can also be used in prefix form, like ++x in which case the value of the expression is the new value of the variable rather than the old value.

6 Technically, that’s not quite true; there are constructs that are not covered in the AP curriculum that allow us to guarantee that certain bits of code execute just before returning from a method.

7 It is legal but unusual to use an empty return statement in a constructor. It can be used to exit from a constructor early but constructors do not return a value; they merely initialize the object that will be the value of the new expression that invoked the constructor.

8 There are other constructs, not covered in the AP curriculum for controlling loop behavior. A break statement causes the current loop to exit immediately while a continue statement causes the current loop to jump immediately to its next iteration.

9 Static methods can, like any code, access instance variables and invoke instance methods if they have a reference to an instance of a class such as by being passed one as an argument or having one stored in a static variable.

10 String objects can also be created by writing a literal string in your program. They are the only class that gets special treatment from the Java compiler. And autoboxing of primitive types can cause new instances of the wrapper types to be created without explicitly calling a constructor.

11 There are other access levels than public and private but they are not covered in the AP curriculum. Occasionally you will see a class with neither a public nor private modifier. One rule of Java is that there can be only one public class per .java file so if you have more than one top-level class in a file all but one of them will have to leave off the public modifier.

12 Correctly implementing an overridden version of equals is actually surprisingly hard but how to do so is not part of the AP curriculum.

13 In the AP Java Quick Reference they list this method as boolean equals(String other). That is not correct but the difference doesn’t matter for anything on the exam.

14 The Integer constructor has been deprecated since Java 9. According to the Javadocs “It is rarely appropriate to use this constructor. The static factory valueOf(int) is generally a better choice, as it is likely to yield significantly better space and time performance.”

15 The Double constructor has been deprecated since Java 9. According to the Javadocs: “It is rarely appropriate to use this constructor. The static factory valueOf(double) is generally a better choice, as it is likely to yield significantly better space and time performance.”

16 Technically a method doesn’t have to call itself directly. There can also be “mutual recursions” where method a calls b which then calls a. But in the AP curriculum we are only concerned with simple one-method recursions.