← Back to Home

Code-Alongs

Overview

Join us for interactive coding sessions where we'll work through real-world examples and practice implementing loops, arrays, UPER problem-solving framework, and pass-by-value concepts in Java.

Available Code-Along Topics

Code-Along 1: Loops

In this interactive session, we'll practice implementing various types of loops in Java:

  • While loops for condition-based iteration
  • For loops for count-based iteration
  • Nested loops for complex patterns and multi-dimensional data
  • Loop control statements (break and continue)

Sample Exercises


// Exercise 1: Sum all numbers from 1 to n using different loop types
int sumWithWhile(int n) {
    int sum = 0;
    int i = 1;
    while (i <= n) {
        sum += i;
        i++;
    }
    return sum;
}

int sumWithFor(int n) {
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += i;
    }
    return sum;
}

// Exercise 2: Print a pattern using nested loops
void printTriangle(int rows) {
    for (int i = 1; i <= rows; i++) {
        for (int j = 1; j <= i; j++) {
            System.out.print("* ");
        }
        System.out.println();
    }
}
                

Code-Along 2: Arrays

Join us to explore array manipulation techniques and common array algorithms:

  • Array declaration and initialization
  • Accessing and modifying array elements
  • Multi-dimensional arrays
  • Common array algorithms (searching, sorting, filtering)

Sample Exercises


// Exercise 1: Find the maximum value in an array
int findMax(int[] array) {
    if (array.length == 0) {
        throw new IllegalArgumentException("Array cannot be empty");
    }
    
    int max = array[0];
    for (int i = 1; i < array.length; i++) {
        if (array[i] > max) {
            max = array[i];
        }
    }
    return max;
}

// Exercise 2: Reverse an array in-place
void reverseArray(int[] array) {
    int left = 0;
    int right = array.length - 1;
    
    while (left < right) {
        // Swap elements
        int temp = array[left];
        array[left] = array[right];
        array[right] = temp;
        
        // Move towards the center
        left++;
        right--;
    }
}
                

Code-Along 3: UPER Problem-Solving Framework

Learn to apply the systematic UPER framework to solve programming challenges:

  • Understand: Clearly define the problem and requirements
  • Plan: Develop a strategy before writing code
  • Execute: Implement the solution methodically
  • Reflect: Evaluate and optimize your solution

Sample Problem

Problem: Given an array of integers, find all pairs of numbers that sum to a specific target.

Understand

  • Input: An array of integers and a target sum
  • Output: All pairs of numbers that add up to the target
  • Constraints: Handle duplicates, handle empty arrays

Plan


// Approach 1: Nested loops (O(n²))
// For each number, check if (target - number) exists in the array

// Approach 2: Using a HashSet (O(n))
// Use a set to track seen numbers and check if (target - current) exists
                

Execute


List findPairs(int[] numbers, int target) {
    List pairs = new ArrayList<>();
    Set seen = new HashSet<>();
    
    for (int num : numbers) {
        int complement = target - num;
        
        if (seen.contains(complement)) {
            pairs.add(new int[]{num, complement});
        }
        
        seen.add(num);
    }
    
    return pairs;
}
                

Reflect

  • Time Complexity: O(n) - single pass through the array
  • Space Complexity: O(n) - for storing the set
  • Edge cases: Empty arrays, no matches, duplicate pairs
  • Potential improvements: Handle duplicates more elegantly

Code-Along 4: Pass-by-value

Explore Java's pass-by-value mechanism and understand its implications:

  • Passing primitive types vs. reference types
  • Modifying object state vs. reassigning references
  • Common misconceptions and mistakes
  • Practical techniques for working with method parameters

Sample Exercises


// Exercise 1: Comparing primitive and reference parameter behavior
void demonstratePassByValue() {
    // Primitives
    int x = 10;
    System.out.println("Original x: " + x);
    modifyPrimitive(x);
    System.out.println("After method call, x: " + x);  // x is still 10
    
    // References
    Person person = new Person("Alice");
    System.out.println("Original name: " + person.name);
    modifyObject(person);
    System.out.println("After modifyObject: " + person.name);  // name is changed
    
    replacePerson(person);
    System.out.println("After replacePerson: " + person.name);  // still the modified name
}

void modifyPrimitive(int n) {
    n = n + 5;  // Only affects the local copy
    System.out.println("Inside modifyPrimitive: " + n);
}

void modifyObject(Person p) {
    p.name = p.name + " (modified)";  // Modifies the actual object
}

void replacePerson(Person p) {
    p = new Person("Bob");  // Only reassigns the local reference
    System.out.println("Inside replacePerson: " + p.name);
}
                

How to Join a Code-Along

  1. Log in to your BloomTech platform account
  2. Navigate to the "Live Events" section
  3. Look for available Backend Development code-along sessions
  4. If no sessions are currently scheduled, please reach out to the Backend Development team to request one

Preparation Checklist

  • Review the module content before attending
  • Set up your development environment
  • Have your questions ready
  • Test your audio and video setup

Contact the BD Team

Need to schedule a code-along session? Have questions? Contact the Backend Development team:

  • Use the #help-backend channel in Slack
  • Reach out to your Team Lead
  • Contact your Section Lead