Computer Systems
Number Systems (Base Conversion)
Basic
Output
System.out.println() print a statement and end the line
System.out.print() only print a statement
System.out.printf() *Not in AP Computer Science A
Input
Scanner class (https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html)
Comment (// one line comment; /* */ multi-line comment; @ Annotations)
Reserved Words (all reserved words in Java are lowercase) (https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html)
Operator Precedence (https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html)
Important Note: Logic AND && has higher priority than logic OR ||.
Data Types
Primitive (values of primitive data types are not objects)
boolean, int, double, char, long, float, short, byte
Casting Conversion
Widening Primitive Conversion (automatic)
Narrowing Primitive Conversion (require casting)
Special Conversion
To convert a number to String, just concatenate it with an empty String (front or back): String s = "" + 25;
To convert an String to an int, use the parseInt function in the Integer class: int n = Integer.parseInt("65");
To convert an String to a double, use the parseDouble function in the Double class: double n = Double.parseDouble("3.14");
Objects
Upcasting (child to parent, automatic); downcasting (parent to child, require casting)
String (https://docs.oracle.com/javase/7/docs/api/java/lang/String.html)
A String is an immutable object.
To compare the contents of two String, use the equals method.
Math Class (https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html)
Relational operators == and != when applied to objects compare the objects' references (addresses) but not their values. Use equals and compareTo methods to compare the values of two objects.
final keyword (if a variable is declared final, then its value cannot be changed once it is assigned.)
Very large number: java.math.BigInteger; java.math.BigDecimal;
Classes and Objects
static keyword (if a variable or a method is declared static, the variable or method belongs to the class not the object, it is shared by all objects of the class. You can call the static method by using the class name not the object name. You don't need to instantiate a object to access the static variable in the class.)
Inheritance (http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html)
keyword extends
Access to Inherited Private Fields - http://ice-web.cc.gatech.edu/ce21/1/static/JavaReview-RU/OOBasics/ooInheritanceAccess.html
A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass using super.
Method Overriding: An instance method in a subclass with the same signature and return type as an instance method in the superclass overrides the superclass's method.
If a subclass constructor does not make an explicit call to a superclass's constructor (using keyword super), then superclass's no-args constructor is called by default. In that case, the superclass must have a no-args constructor.
Access to Members of a Class (https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html)
Control Structures
Conditional Statements
? : Ternary Operator (shorthand for if-then-else statement)
Loops
break
continue
Nested Loops
Arrays and ArrayLists
Arrays (once an array is created, its size cannot be changed.)
int[] arr = {1,2,3}; the curly bracket notation can only be used in the initialization. Afterward, it must be changed to arr = new int[]{4,5,6}.
2-D arrays can be rectangular or jagged. (Important Note: For the purpose of the AP Computer Science A Exam, students should assume that 2-dimensional arrays are rectangular (not ragged) and the elements are indexed in row-major order.)
Convert an Array arr to String. (Ex. Arrays.toString(arr))
Convert a multidimensional Array arr to String. (Ex. Arrays.deepToString(arr))
ArrayLists (https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html)
arr.toArray()
arr.toArray(String[] :: new)
Recursion
Sorting and Searching Algorithms
Sorting
Selection Sort [O(n^2)]
Insertion Sort [O(n) -> O(n^2)]
Merge Sort [O(n log(n))]
Quicksort [O(n log(n)) -> O(n^2)]
Searching
Sequential Search [O(n)]
Binary Search [O(log(n))]
Data Structure
Common Exceptions
Catching Exceptions
Other
Exit Program: System.exit(0);