Sprint 2 Notes
Sprint 2 Notes
Unit 1: Primitive Types
- Data Types: int, double, boolean, char
- Variable Declaration: int x = 5;
- Arithmetic: +, -, *, /, %, precedence rules (PEMDAS)
- Casting: int to double, double to int (truncation)
- Input: Scanner sc = new Scanner(System.in);
- Output: System.out.println();
Unit 2: Using Objects
- Objects: Created with new
- Strings: String str = “hello”;
- Methods: length(), substring(), indexOf(), charAt()
- Null References: null
- Equality: == (reference), .equals() (content)
- Math Class: Math.pow(), Math.sqrt(), Math.random()
Unit 4: Iteration
- Loops:
- while(condition) { }
- for(initialization; condition; update) { }
- do { } while(condition);
- Break/Continue: Exit or skip loop iteration
- Nested Loops: Loop inside another loop
- Loop Applications: Traversing arrays, searching, counting
Unit 5: Writing Classes
- Class Anatomy: Fields, methods, constructors
- Constructor: Initializes object state
- public ClassName(type parameter) { }
- Accessors (Getters): Return field value
- Mutators (Setters): Modify field value
- Static Members: Shared across all instances
- Encapsulation: Use private fields and public methods
Unit 6: Array
- Declaration: type[] arrayName = new type[size];
- Access Elements: array[index]
- Iteration: Use loops to traverse arrays
- Common Operations: Finding max/min, sum, average
- Bounds Checking: Avoid ArrayIndexOutOfBoundsException
Unit 7: ArrayList
- ArrayList Declaration: ArrayList list = new
- ArrayList<>();
- Methods:
- add(), remove(), set(), get(), size()
- Dynamic Resizing: Can grow or shrink as needed
- Iteration: For-each or standard for loop
- Autoboxing/Unboxing: Convert between primitives and wrapper objects
Unit 8: 2D Arrays
- Declaration: type[][] arrayName = new type[rows][cols];
- Access Elements: array[row][col]
- Iteration: Use nested loops for row-column traversal
- Applications: Grids, matrices
- Common Algorithms: Row-wise, column-wise processing
Unit 9: Inheritance
- Inheritance: class Subclass extends Superclass
- Subclass: Inherits fields/methods from superclass
- Method Overriding: Redefine superclass method in subclass
- Super Keyword: Call superclass constructor/method
- Polymorphism: Use superclass reference for subclass object
- Object Class: All classes inherit from Object