Lessons

  1. Lesson 32 - Binary Search


    Slides

  2. Lesson 31 - Recursive Techniques


    Slides

    ClassworkHomework

  3. Lesson 30 - Recursion


    Slides

    Homework

  4. Lesson 29 - Linked List


    Slides

    Lab

  5. Lesson 28 - Abstract Classes and Interfaces


    Slides

    Lab

  6. Lesson 27 - args main method


    args in public static void main(String[] args)

    Every Java program starts running from the main method. You’ve seen it many times:

    public static void main(String[] args)
    

    But what’s the purpose of String[] args?

    It allows your program to receive input from the command line.

    When you run your program from the terminal, you can pass extra data directly to it. Those pieces of data are stored in an array called args.

    What exactly is args?

    • args is a String array.
    • When you run a java program, each space-separated item typed after the program name becomes one element in that array.

    For example, if you run:

    java MyProgram hello world 1
    

    Then inside your program:

    • args[0] is "hello"
    • args[1] is "world"
    • args[2] is "1"
    • args.length is 3

    Even though "1" looks like a number, it is still a String, because all command-line arguments start as strings.

    How do you use these arguments?

    Here’s a example that prints whatever the user typed:

    public class Fruits {
        public static void main(String[] args) {
            for (int i = 0; i < args.length; i++) {
                System.out.println("Argument " + i + ": " + args[i]);
            }
        }
    }
    

    If you run:

    java Fruits apple banana cherry 1
    

    Output:

    Argument 0: apple
    Argument 1: banana
    Argument 2: cherry
    Argument 3: 1
    

    Converting the arguments

    Since every element of args is a String, you must convert values to numbers if needed:

    int x = Integer.parseInt(args[3]);
    double y = Double.parseDouble(args[3]);
    

    Exercise

    Add two numbers from the command line

    public class AddNums {
        public static void main(String[] args) {
            if (args.length < 2) {
                System.out.println("Please enter two numbers.");
            }
    
            int a = Integer.parseInt(args[0]);
            int b = Integer.parseInt(args[1]);
            int sum = a + b;
    
            System.out.println("The sum is: " + sum);
        }
    }
    

    Running:

    java AddNums 8 12
    

    Output:

    The sum is: 20
    

    Classwork

  7. Lesson 26 - Random


    Slides

    Classwork

  8. Lesson 25 - Sorting Algorithms


    Slides

    Classwork/Homework

    Bubble Sort

  9. Lesson 24 - ArrayList Hierarchy


    Slides

  10. Lesson 23 - Polymorphism


    Slides

    Classwork/Homework

    Complete the exit-ticket on GoogleClassroom.

  11. Lesson 22 - Inheritance (part 2)


    Slides

    Classwork/Homework

  12. Lesson 21 - Inheritance (part 1)


    Slides

    Demo

    Homework

  13. Lesson 20 - File Handling


    Slides

    Classwork

    Homework: Finish CW.

  14. Lesson 19 - ArrayList


    Slides

    Classwork

    Homework

  15. Lesson 18 - Wrapper Classes


    Slides

    Classwork

  16. Lesson 17 - Exceptions


    Slides

    Classwork: Add exceptions to your SuperArray lab.

  17. Lesson 16 - SuperArray


    Slides

    Classwork - Homework

  18. Lesson 15 - Static Methods and Variables


    Slides

  19. Lesson 14 - Objects and Classes


    Part 1

    Part 2

    Example

  20. Lesson 13 - Methods, arguments/parameters, Java pass by value


    Slides

    Classwork

  21. Lesson 12 - 2D Arrays


    Slides

    Classwork

  22. Lesson 11 - More about Arrays


    Slides

    Classwork/Homework

  23. Lesson 10 - Arrays


    Slides

    Classwork/Homework

  24. Lesson 09 - String Methods, Math Class


    Slides

    Classwork: GoogleClassroom assignment

  25. Lesson 08 - Strings and Loops


    Slides

    Java Visualizer

    Homework

  26. Lesson 07 - Java Memory Architecture and Strings


    Slides

    Classwork

    Homework

  27. Lesson 06 - User Input


    Slides

    Classwork

    Homework

  28. Lesson 05 - Casting


    Slides

    Classwork

    Homework

  29. Lesson 04 - Expressions and Assignment Statements


    Slides

    Classwork

  30. Lesson 03 - Data Types and Varialbes


    Slides

  31. Lesson 02 - Intro to Java


    Slides

  32. Lesson 01 - Git


    GitHub

    Read the Git and GitHub documentation provided in the Tools section.

    Git Commands: When to Use Them

    git clone

    When to use:
    Use this the first time you want to copy a remote repository (e.g., from GitHub) to your computer.

    Command:

    git clone <repository_ssh_url>

    Tip: Run this only once per project. After that, use git pull to update your local copy.

    git pull

    When to use: Use this to bring in the latest changes from the remote repository to your local repository.

    Command:

    git pull

    Tip: Always run this before starting new work to make sure your files are up to date.

    git add

    When to use: Use this to stage (mark) new or modified files that you want to include in the next commit.

    Command: For one file git add <file_name> For all changes git add .

    git commit

    When to use: Use this after git add to save a snapshot of your staged changes in the local repository.

    Command:

    git commit -am "Describe the change you made"

    Tip: Write clear and meaningful commit messages so you and others understand the change.

    git push

    When to use: To send your committed changes from your computer to the remote repository (e.g., GitHub).

    Command:

    git push

    Typical Workflow

    1. git pull: get the latest updates.

    2. Edit your code/files.

    3. git add: if new files have been added or to stage your changes.

    4. git commit -am "message": save your changes locally.

    5. git push: upload your changes to GitHub.