Unit 1 Key Points
- Primitive Types: int, char, double, boolean (lowercase)
- Reference Types: Arrays, Strings, Objects, Classes (uppercase)
- Wrapper Classes: Turn primitives into objects
- Memory Allocation:
- Stack Memory: Stores temp variables (primitives and object references), LIFO
- Heap Memory: Stores objects and arrays (dynamic memory)
- Primitive Passing: Doesn't change the caller's value
- Wrapped Primitives: Allows modification of the original
Unit 2 Key Points
- Object: Created from a class
- Class: Blueprint for objects; groups attributes
- Constructor: Special function to create instances
- New: Creates a new object
- This: Refers to class variables
- Void Method: No return type
- Method Signature: Defines how a method behaves before implementation
- Java Method Parameters:
- Rule 1: Passed in order
- Rule 2: Separated by commas
- Rule 3: Include datatype and name
- Rule 4: Referenced by name inside method
- Non-Void Method: Returns a value (int, string, etc.)
- Escape Sequence: "\" used for formatting
- String Methods: length(), substring(), indexOf(), equals(), compareTo()
- Wrapper Classes: Turn primitives into objects
Unit 3 Key Points
- Java Relational Operators:
- equal to: ==
- not equal to: !=
- less than: <
- greater than: >
- less than or equal to: <=
- greater than or equal to >=
- Else statement purpose: handles what happens if condition is false
- If-Else statement structure:
if (condition) {
// do something
}
else {
// do something else
}
- Else If statements purpose: handling multiple conditions
- Nested Conditional statement: statement inside statement
- Compound Conditional statement: 2 or more conditions are combined into a single if statement (using logical operators)
- && (AND): (returns true only if both conditions are true)
- || (OR): (returns true if at least one condition is true)
- ! (NOT): Negation of statement
Unit 4 Key Points
- While loops: run until condition is false
- Syntax:
while (i < value) {
// do something
i++;
}
- Similarly, for loops run until condition is false
- Syntax:
for (i = minValue,i < maxValue, i++) {
// do something
}
- For each loop: used for iterating through items in a list:
- Syntax:
for (int element : list) {
// do something
}
- Iteration of index through string requires charAt(i)
- substring method divides string at provided starting/ending index values
- .split() splits a string into array based on what is provided in the argument and where it occurs in the string.
Unit 5 Key Points
- Class Declaration: starting point of any class. Includes class keyword, class name, and access modifiers.
- Instance Variables: attributes of class, declared inside class but outside any methods, normally set as private
- Constructor: special method called when an object is instantiated, no return type
- Default constructor: constructor w/o parameters, defined by compiler automatically if not defined
- Overloaded constructor/Parameterized constructor: constructor that accepts parameters to initialize fields
- No-arg constructor: no parameters, defined by a programmer
- Methods: define behaviors of class:
- Accessor: (getters): retrieve field values
- allows other objects to obtain the value of instance or static variables
- toString accessor Method: overriden method used to provide description of an object
- Mutator: (setters): modify/set field values
- Types of methods:
- Instance Methods: Methods that belong to an instance of a class Instance methods require an object of the class to be used. They operate on objects of the class.
- Can access instance variables and other instance methods within the class
- Can access static variables and methods
- "this" keyword: references object itself or object's instance variables, methods, constructors, etc.
Unit 6 Key Points
- Arrays: collection of primitive or object reference data
- length has datatype public final because it can be accessed anywhere and cannot be changed
- negative indexing does not work in Java
- cannot add or remove elements
- updating element values is allowed
- default values when an array is instantiated
- You can traverse through arrays using for loop or for each loop:
- Syntax for "for" loop:
for (int i = 0, i < array.length, i++) {
System.out.println(i);
}
- Syntax for "for each" or "enhanced for" loop:
for (i : array) {
System.out.println(i);
}
- Can traverse using while loops as well
Unit 7 Key Points
- ArrayList: resizeable array, can add or remove elements since length is not final
- Requires use of import statement: import java.util.ArrayList;
- Initializing ArrayList example: ArrayList<Integer> numbersList = new ArrayList<>();
- methods such as size, add, get, set, remove
- traverse with for loop, enhanced for loop, while loop
- Linear searching: iterates through whole list until target is found
- Selection sort: identifies either the maximum or minimum of the compared values and iterates over the structure checking if the item stored at the index matches that condition, if so, it will swap the value stored at that index and continue
- Insertion sort: inserts each value it finds at the appropriate location in the data structure
Unit 8 Key Points
- 2D array: array of arrays, created & indexed similar to 1D array
- Declaration of 2D array: int[][] 2DArrayName = new datatype[# of rows][# of columns]
- Use curly braces if you want to actually put values in the 2D array
- Each row of 2D array has its own initializer list
- Traversing 2D arrays:
- requires use of nested loops
- outer for loop: iterates through rows
- inner for loop: iterates through each value in the row
- Linear searching: iterates through whole list until target is found
- Binary searching: divide list repeatedtly in half (lower and upper half) until element is found, requires less steps than linear search
- Global sorting steps:
- create 2D array
- flatten 2D array (use nested loops to copy elements from 2D array into 1D array)
- sort 1D array
- reshape back into 2D array
- print out 2D array
Unit 9 Key Points
- Inheritance Basics: Allows subclass to inherit properties and behaviors from superclass; promotes code reuse.
- Superclass: Parent class; provides attributes and methods to subclasses.
- Subclass: Inherits from superclass; can extend or override methods, add new attributes.
- Method Overriding: Subclass modifies inherited methods from the superclass.
- Polymorphism: Subclass objects treated as superclass instances; dynamic method calls at runtime.
- super Keyword: Refers to superclass; used to access superclass constructor or overridden methods.
- Object Class: Root of Java class hierarchy; all classes inherit from it.
- Class Hierarchies: Multi-level inheritance creates complex class relationships.
- Overriding vs Overloading: Overriding changes method behavior in subclass; overloading uses same method name with different parameters.