The official resource: https://docs.oracle.com/javase/tutorial/java/index.html The official subset: Terms: === Comments: // single line /* multiple lines */ /** Used for Javadoc */ Don't put too many: Write a clear code! // Hello-World in three ways 1. Console: javac Main.java <-- Compiler java Main 2. IDE (Integrated Development Environment) 3. GUI Compilation errors (wiggly red lines included) : Everything that is discovered BEFORE running the program. Syntax for example. Run-Time errors : Discovered only when running the program. For example, dividing by zero. Logic errors: The program works as you planned, but the results are wrong. Declarations and statements are terminated with semicolon ';' Statements can be grouped by using braces '{' and '}' Naming: (of variables, classes, functions) Can use letters (uppercase, lowercase), digits, and underscore '_' No name can start with a digit (underscore is ok) Reserved Java names are not allowed note: All Java reserved words are only lowercase letter Convention: Classed start in Capital letter: BankAccount methods and variables start in lowerCase, using camelCase convention: addInterest( double sum) Constants may use all capitals and underscore between words: SUN_DISTANCE Reserved words (keywords). About 53 of them. Examples: public, private, static, void, int, double Need one and only: public static void main(String[] args) This is where the program starts. === Primitive types INTEGER: byte, short, *int*, long FLOATING POINT: float, *double* BOOLEAN: *boolean* CHARACTER: char Only int, double, boolean are tested in the AP exam. Specifically, char is not!! String is NOT primitive type. An Object. (different #bytes in memory) int: In Java, int is 4 Bytes. Max value: 2^31-1 Min value: -2^31. 2's complement. Integer arithmetic % modulus (same rank as / and *) pre/post ++ += : compound assignment boolean: true, false 1 Byte char: 1 Byte! ASCII code: 256 possible values. --- CPU, ALU BIT - Binary digIT Byte = 8 bits 1K = 1024 = 2^10 ~= 1e3 1M = 2^20 ~= 1e6 1G = 2^30 ~= 1e9 Word: Depending on OS/CPU. The basic unit of bits processed by the CPU. --- casting: Type of result depends only on the type of operands. a / (double)b Only two casts tested: (int) and (double) Promoting data types: double + int --> double --- Relational operators: ==, !=, <,<=, >, >= --- Arithmetic operators: + , - , * , / , % --- Assignment operators: = , += , -=, *=, /=, %= --- String operator: String concatenation: + --- Logical operators: || , &&, ! DeMorgan's law: (prove by Truth table) !(P && Q) = !P || !Q !(P || Q) = !P && !Q ===== Not part of the AP operators: bitwise , shifts >> or << conditional ()? : --- flow control: if ( condition_boolean ) { } while ( condition_boolean ) { } Patterns: int idx=0; while (idx ASCII of char, Peeling. Binary ,hex, decimal Integer is 4 bytes, plus and minus, so: -2^31 to 2^31-1 Byte: char: 0 to 255 Boolean true , false if (condition) { } else { } Things you do not need to master, just know they exist: switch() (...) ? oneCase : twoCase === Patterns: 1. Go over elements of a String: for (int i=0; ii0 && i=0 ; i--) 4. Going in jumps: for (int i=0; i<10; i+=2) 5. indexOf is jumping around --> Works well with while() 6. for_loops are for going on all elements, one by one. * COMMENTing not working code. Don't destroy. === Variables: Local variables - Within a method Instance variables - Non static fields of a class Class variables - Static fields Parameters - Values to methods Scope of variables === Methods: same naming rules as variables. Common: camelNotation [Modifier: public, private] returnType methodName ( [parameterList] ) [exceptionList] { [methodBody] } Minimal: returnType methodName ( ) { } Method signature: Name + argumentList . NOT return type. Overloading methods: different by the type and number of arguments. public void draw(String S){} public void draw(int i){} public void draw(double d){} Pass by value - Switch program === SPECIAL METHODS public static void main(String[] args) in applications init() in JFrames (though you won't need to write JFrames on final) paint() in JFrames repaint()--used to invoke paint() in JFrames GUI TERMS EVENTS (clicks, keypresses, etc.) LISTENER (MouseListener, MouseMotionListener, ActionListener) (need to know what they do for final, but won't need to write code with them) === Class One class per file. Same name as file. Keywords: class, public/private/protected (<- no need to know protected), static, import, final Constructor(s): same name as class not return type specified can have multiple constructors Fields, aka Instance variables Methods, aka functions Object: An instance of the class. Accessors / Selectors Modifiers / Mutators toString() Converts the object to a string this Static methods/variables : Class .vs. instance . Account number. Static method - belongs to the Class. No need for object to get it rolling. for example, Math.random() Another example: accountNumber Does not have the normal object variables. Non static method: Needs an object! Have the object variables, context (this). === Inheritance OOP: Encapsulation Keyword: extends Keyword: implements super: dot notation super: constructor Methods: New Overloading Reusing the super Interface class: Comparable Return value of -1,1,0 Abstract class: Recursion Base case Recursive call === ARRAYS AND ARRAY-LIKE STRUCTURES ARRAYS (e.g., double[] testScores) MULTIDIMENSIONAL ARRAYS (e.g., boolean[][] isAlive) ARRAYLISTS (e.g., ArrayList a) Array int[] A; // declaring // right now, A[0] will be an error: No memory assigned yet!! A = new int[9]; // Assigns space in memory // indexing: 0 .. (A.length-1) int[] B = {1,2,3}; String[] S = {"first","second"}; 2D Arrays: int[][] A2; A2.length <-- Number of rows A2[0].length <-- number of columns Nested for loops: for (int rr=0; rrmax) max = A[ii]; Alternative: max = A[0]; 3. Boolean flag: boolean addThese = true; ... 4. Adding (and removing) values IS tricky: The array doesn't shrink nor stretches. ==== Debugging 0. READ the error message. 1. Look again, with critical eyes (Syntax..) 2. If it's syntax: try and write again! 3. Run time error: step through the code. With specific example, or specific value. 5. Rewrite in different way. === End ===