ECE366 - Lesson 1

Course Overview, Course Tools/IDE, Github Review, Intro to Java and Docker

Instructor: Professor Hong

Intros

  • Name, Major, Year
  • What do you hope to get out of this class?
  • An interesting fact about yourself

Before we begin...

  • Github Setup
  • Install IntelliJ
  • Install Docker
## Setting up Github Locally Create a github account (if you don't already have one). Set up your github user name and email: ``` git config --global user.name "Your Name" git config --global user.email "yourEmail@cooper.edu" ``` Set up your ssh key (note directory may be different): ``` ssh-keygen -C "yourEmail@cooper.edu" -t rsa cat .ssh/id_rsa.pub ``` Copy the key and put it in your account settings. More info can be found [here](https://help.github.com/articles/connecting-to-github-with-ssh/).
## Installing IntelliJ & Java - Create an IntelliJ student account [here](https://www.jetbrains.com/shop/eform/students). - Download IntelliJ Ultimate Edition [here](https://www.jetbrains.com/idea/download). - Run IntelliJ and set up JDK21. - Linux/Unix Terminal Installation of Java: ``` $ sudo apt-get update $ sudo apt install openjdk-21-jdk-headless ```
## Installing Docker - Set up Ubuntu for Windows [here](https://learn.microsoft.com/en-us/windows/wsl/install). - Install Docker for Windows [here](https://docs.docker.com/desktop/windows/wsl/). - Install Docker for Mac [here](https://docs.docker.com/desktop/install/mac-install/). - Ensure that docker is runnable on the command line. For example: ``` docker --version Docker version 27.4.0, build bde2b89 ```

Syllabus

https://cooperunion.sharepoint.com/:w:/s/Section_ECE-366-1-2025SP/EcWn_TZpyyVBjSHRT702_34BvdoDGyKqVy-FhCVGjXlyew?e=jnwz5z

Semester Project

https://cooperunion.sharepoint.com/:w:/s/Section_ECE-366-1-2025SP/EWZlRvN_topAo_kYhIuUo0EBE0MGQtCVWo34q1BYUeVbGQ?e=1rAiou
## Github Review [https://github.com/ECE366-Spring2024/github_review](https://github.com/ECE366-Spring2025/github_review)
## Github Branches and Forks - Fork the repository - Clone the repository from your fork. For example: ``` git clone git@github.com:hong3cooper/github_review.git ``` - Make a branch ``` git checkout -b myBranch ``` - Make an edit to the README.md - Commit the edit and push ``` git status git add README.md git status git commit -m "Updated README" git push origin myBranch ```
## Github Pull Request - Go to the original repository [here](https://github.com/ECE366-Spring2025/github_review) - Go to "Pull Requests" and create a new pull request - Select the appropriate branches (make sure to click compare across forks) to open a pull request - Enter appropriate documentation
## Github Issues - Go to the Issues tab and add new issues - You can add tags and milestones as appropriate - Example: [https://github.com/ECE366-Spring2025/github_review/issues](https://github.com/ECE366-Spring2025/github_review/issues)
## Intro to Java
## Hello World in Java - Open IntelliJ and create a new Java Project with no sample code - Create a new Java Class in src called Main.java ``` public class Main { public static void main(String[] args) { System.out.println("Hello world!"); } } ``` - Run the code in IntelliJ with the ▶️ button or in the command line: ``` java Main.java ```
## Roll the Die Game - Create a game where the user will roll 6 die. - They win if they roll a total of 20. - If they roll a total of something other than 20, they lose. - Let them know what they lost by. - We will use conditionls and loops in this example.
## Roll the Die Game ``` import java.util.Random; public class RollTheDieGame { public static void main(String[] args) { int lastSpace = 20; int currentSpace = 0; int maxRolls = 5; Random random = new Random(); System.out.println("Welcome to Roll the Die! Let's begin..."); for (int i=0; i<=maxRolls; i++) { int die = random.nextInt(6) + 1; currentSpace += die; System.out.print(String.format("Roll #%d: You've rolled a %d.", i, die)); if (currentSpace == lastSpace) { System.out.print("You're on space " + lastSpace + " spaces. Congrats, you win!"); break; } else if(i==maxRolls && currentSpace < lastSpace) { System.out.print("You're on space " + currentSpace + "."); System.out.println("Unfortunately, you didn't make it to all " + lastSpace + " spaces. You lose!"); } else { int spacesToGo = lastSpace - currentSpace; System.out.print("You are now on space " + currentSpace + " and have " + spacesToGo + " more to go."); } System.out.println(); } } } ```
## Intro to Docker
## What is Docker? - An open platform for developing, shipping, and running applications. - Pulls images from online / Docker Hub - Sets up a container - Runs various commands like Java
## Hello World via Docker Hello.java ``` public class Hello { public static void main(String[] args) { System.out.println("Hello World"); } } ``` Dockerfile ``` FROM eclipse-temurin:latest ADD . /app WORKDIR /app CMD java Hello.java ```
## Docker Commands Build the docker image ``` docker build -t hello-world . ``` View the available docker images ``` docker images ``` Run an instance of the docker image ``` docker run --name hello-world-app hello-world ``` Note that the container ran and stopped ``` docker container ls -a ```
## Docker Bash Shell Start another container in the background (-d), keeps STDIN open (-i), with a pseudo-TTY/terminal (-t), with a shell session ``` docker run --name hello-world-app2 -d -i -t hello-world /bin/sh ``` Go into the container ``` docker exec -it hello-world-app2 bash ``` Now you can run Unix commands inside the container like a Unix terminal. You can quit with: ``` exit ```
## Cleaning Up Docker Remove a container ``` docker rm hello-world-app ``` Stop a running container before you remove it ``` docker stop hello-world-app2 docker rm hello-world-app2 ``` Remove an image ``` docker rmi hello-world ``` Extreme cleanup of everything ``` docker system prune -a ```
## Another Example in class