Add Day 1 of java class

This commit is contained in:
2020-11-08 17:07:45 -05:00
parent 5741abcc62
commit 1d5d0188b1
104 changed files with 695 additions and 1 deletions

162
docs/day0.md Normal file
View File

@@ -0,0 +1,162 @@
# Day 0
When you start programming half the battle is getting your bearings. Suddenly it matters where you put your files. You need to know where you home directory is, you need to understand file permissions, you need to understand what a file actually *is*. Trying to program without first learning about *the thing you are programming* will cause headache.
Fortunately we can do some things to make your life easier. We can install an **Integrated Development Environment (IDE):** a program that lets you visualize your files and folders and quickly switch between them. We can install a **version control system (VCS)** that will let you "snapshot" your code and save it to the cloud so you never lose it. We can organize our project to be repeatable, and more importantly, un-loseable.
## I have a Windows PC
(or skip to [I have a Mac](#i-have-a-mac))
### Install Git (windows)
Git is a version control program, but you can think of it as your best friend in the cold, dark world of data loss. Git will make sure you don't lose progress. It lets you save your code at various stages and revert to previous saves if you need to. Like mentioned above, it takes a "snapshot" of your code at that point in time.
1. Head to <https://git-scm.com/>
2. Click Download
![git_download](img/day0/git_download_windows.png)
3. Run through the default install process
### Install Java (windows)
1. Head to <https://ninite.com>
2. Under the **Developer Tools** section, check the **JDK (AdoptOpenJDK) x64 8** option and then **Get Your Ninite**
![download_for_windows](img/day0/ninite_download_for_windows.png)
3. Once the file has finished downloading, click on the installer to Run through the install process.
![java_windows_install](img/day0/ninite_install_for_windows.png)
### Add Java to path (windows)
1. Open the File Explorer, and navigate to `C:\Program Files\AdoptOpenJDK\jdk-8.x.xxx\bin`
2. Copy the path to your clipboard
![java_windows_path](img/day0/java_windows_path.png)
3. Now click the Windows Start Button
4. Start typing **environment**
5. Click on **Enter the System Environment variables**
![widnows_edit_env_vars](img/day0/windows_env_var.png)
6. Click on **Environment Variables..**
7. Under the *System Variables* section, find and click the **Path** entry and then click **Edit**
![windows_sys_env_var_path](img/day0/windows_path_edit.png)
8. Click **New** and paste in the path copied in Step 1 and click **OK**
![windows_path_edit](img/day0/windows_path_edit2.png)
9. Reboot your computer
### Install BlueJ (windows)
Your most important tool as a programmer is a proper editor. It should offer you a wide selection of tools but get out of your way when you don't need it
. While there are manny advanced editors and IDEs out in the wild, its always good to start with the basics, to get a proper grasp and understanding of the
language.
1. Head to <https://bluej.org/>
2. Click on the download link
![BlueJ_download](img/day0/bluej_download.png)
3. Run through the installer, select default options
![bluej_install](img/day0/windows_bluej_install.gif)
4. Open BlueJ
![bluej_open](img/day0/bluej_open.png)
### Create a "Projects" folder (windows)
I keep all my projects in a folder called "Projects" in my home directory. On Windows this is at `C:\Users\<your username>\Projects`. Create this folder now. Bookmark it, put it in your favorites, don't lose it.
1. In BlueJ, go to the **Project** menu and click on **New Project**
2. For the Name, enter `java_game`, for the Location, select the `Projects` folder you created in the step above.
![ctrl_ko](img/day0/windows_create_bluej_project2.gif)
## I have a Mac
### Install Git (mac)
Git is a version control program, but you can think of it as your best friend in the cold, dark world of data loss. Git will make sure you don't lose progress. It lets you save your code at various stages and revert to previous saves if you need to.
1. Head to <https://git-scm.com/>
2. Click Download
![git_download](img/day0/git_download_mac.png)
3. Run through the default install process
### Install Python (mac)
1. Head to <https://adoptopenjdk.net/>
2. Select **OpenJDK 8 (LTS)** for version, and **HotSpot** for JVM and click the **Latest Release** download button
![download_java_mac](img/day0/mac_install_java.png)
3. Follow the standard install process
![java_install_for_mac](img/day0/mac_bluej_install2.gif)
### Install BlueJ (mac)
Your most important tool as a programmer is a proper editor. It should offer you a wide selection of tools but get out of your way when you don't need it
. While there are manny advanced editors and IDEs out in the wild, its always good to start with the basics, to get a proper grasp and understanding of the
language.
Your most important tool as a programmer is a proper editor. It should offer you a wide selection of tools but get out of your way when you don't need it
. While there are manny advanced editors and IDEs out in the wild, its always good to start with the basics, to get a proper grasp and understanding of the
language.
1. Head to <https://bluej.org/>
2. Click on the download link
![BlueJ_download](img/day0/bluej_download_mac.png)
3. Click on the BlueJ mac zip that was downloaded to automatically unzip the file
4. In the BlueJ folder that was just created, drag `BlueJ.app` to your `Applications` folder
![BlueJ_Drag](img/day0/mac_bluej_drag.gif)
5. Open BlueJ
![bluej_open](img/day0/bluej_open_mac.png)
### Create a "Projects" folder (mac)
I keep all my projects in a folder called "Projects" in my home directory. On Windows this is at `/Users/<your username>/Projects`. Create this folder now. Bookmark it, put it in your favorites, don't lose it.
1. In BlueJ, go to the **Project** menu and click on **New Project**
![bluej_project_new_mac](img/day0/bluej_project_new_mac.png)
2. For the Name, enter `java_game`, for the Location, select the `Projects` folder you created in the step above.
![bluej_choose_project](img/day0/bluej_choose_project2.gif)

258
docs/day1.md Normal file
View File

@@ -0,0 +1,258 @@
# Day 1
Before we can dive into our web project we have to cover some Python basics. Let's talk about writing a python program.
## The Interactive Python Prompt
1. Make sure you have a (venv) to the left of your terminal cursor. Type `python` and press enter.
**NOTE**: This is not a terminal! You cannot run your django server from here. Before you can do things in the terminal you must exit by typing `exit()`!
![python_prompt](img/day1/python_prompt.gif)
2. Type `1+1` and press enter. You should see `2` returned. As long as you see the `>>>` to the left of your cursor you can type any python code you want and press enter to execute it.
3. Type `x=1` and press enter. Nothing should return.
4. Type `x` and press enter. You should see `1` return. We've give `x` the value of `1`
5. Type `x+1` and press enter. You should see `2` returned just like `1+1` above.
6. Type `x=3` and press enter. Nothing should return.
7. Type `x` and press enter. You should see `3` return. Variables in Python can be reassigned to anything else.
8. Type `x="hello"` and press enter. Nothing should return.
9. Type `x` and press enter. You should see `hello` printed to the screen. Variables in python do not have a "type" - they can be integers, strings, floats, etc and can switch between them at will.
10. Type `my_name = "<your name here>"` and press enter. Nothing should return
11. Type `my_name` and press enter. You should see your name printed to your terminal. `my_name` is a much better variable name than `x`. It describes the thing it stores. Please use variable names that are descriptive.
12. Type `my_coordinates = (1,2)` and press enter. Nothing should return.
13. Type `my_coordinates` and press enter. `(1,2)` should return. This is called a `tuple`. It's useful for storing multiple points of data.
14. Type `address = (123, "lane ave", "Columbus", "OH", 43212)` and press enter. Nothing should return
15. Type `address` and press enter. You should see the address print to the terminal. Tuples can hold multiple types of data - 123 is a number and "lane ave" is a string.
16. Type `len(address)` and press enter. You should see `5` printed to the terminal. There are 5 "things" in the tuple:
(1) `123`
(2) `"lane ave"`
(3) `**"Columbus"`
(4) `"OH"`
(5) `43212`
17. Type `address[0]` and press enter. You should see `123` printed to the terminal. You just accessed the first item in the tuple. Tuples and other collections start at 0 and count up.
18. Type `address[1]` and press enter. You should see `"lane ave"` print to the terminal. You just accessed the second item in the tuple
19. Type `vocabulary = {"apple": "the usually round, red or yellow, edible fruit of a small tree, Malus sylvestris, of the rose family.", "banana": "a tropical plant of the genus Musa, certain species of which are cultivated for their nutritious fruit."}` and press enter. Nothing should return.
20. Type `vocabulary` and press enter. {"apple": ...} should print to the terminal. This is called a dictionary.
21. Type `vocabulary["apple"]` and press enter. `'the usually round, red or yellow, edible fruit of a small tree, Malus sylvestris, of the rose family.'` should print to the terminal. You just access the definition of apple. Much like tuples can be accessed with `address[0]` or `address[1]`, dictionary values can be accessed by supplying the keyword, or key for short.
22. Type `exit()` and press enter. You should no longer see `>>>` to the left of the cursor.
## A Python Program
1. Create a new file called `my_program.py` by clicking the "add file" icon in the top left of VSCode.
![add_file](img/day1/add_file.png)
![name_file](img/day1/name_file.png)
![open_file](img/day1/open_file.png)
2. In this file type `print('hello, world!')` and save with ++ctrl++ + S
![type_hw](img/day1/type_hw.png)
3. In the terminal type `python my_program.py` and press enter. You should see `hello, world!` printed to the terminal.
![run_hw](img/day1/run_hw.gif)
4. Congratulations! You ran your first python file. Just like the python command prompt above, running `python <filename>` on a file with python code in it will execute that python code. Now we can run multiple lines of python at once!
5. Below `print('hello, world!')` type `print('goodbye!)`
![print_goodbye](img/day1/print_goodbye.png)
6. Below `print('goodbye')` type
```python
x = 1
y = 2
print(x + y)
my_name = "<your name>"
print(my_name)
```
![type_more_code](img/day1/type_more_code.png)
7. Save the file with ++ctrl++ + S. In your terminal type `python myprogram.py` and press enter. You should see
```bash
hello, world!
goodbye!
3
Reese
```
printed to the terminal
8. This is out of order. We want to print "goodbye" last. Let's fix that with functions.
9. Above `print('hello, world!')` type `def print_hello():`
![def_ph](img/day1/def_ph.png)
10. Indent `print('hello, world!')` by pressing ++tab++
![indent_hw](img/day1/indent_hw.png)
11. Give 'goodbye' the same treatment. This time type `def print_goodbye():`
![print_gb](img/day1/print_gb.png)
12. Finally add `def middle_stuff():` above the remaining cod
![middle_stuff](img/day1/middle_stuff.png)
13. Save the file with ++ctrl++ + S. Now type `python my_program.py` in the terminal and press enter. Nothing will return.
![functions_in_order](img/day1/functions_in_order.png)
14. We've given our snippets of code "names" by adding a "def" above them. These are called functions. We can call them in any order we want. Let's call them in the correct order by using their names. Add the following to the bottom of my_program.py
```python
print_hello()
middle_stuff()
print_goodbye()
```
15. Type `python my_program.py` in the terminal and press enter. Now everything prints in order!
![in_order](img/day1/in_order.png)
## A Django Project
Now that we can write some basic python we can begin our django project. Let's start by creating a view.
1. Close out of my_program.py
2. In the terminal type `django-admin startapp mysite`
![startapp](img/day1/startapp.gif)
3. Expand the `config` folder by clicking on it
![config](img/day1/config.png)
4. Click on `settings.py` to open it
5. Scroll down to line 33 and add `mysite` above `'django.contrib.admin'`
![add_mysite](img/day1/add_mysite.png)
6. Save with ++ctrl++ + S
7. Click on `urls.py` to open it
![urls](img/day1/urlspy.png)
8. On line 17 add `, include` after `from django.urls import path`
![include](img/day1/include.png)
9. Add `path('', include('mysite.urls')),` above `path('admin/', admin.site.urls),`
![mysiteurls](img/day1/mysiteurls.png)
10. Expand the newly created `mysite` folder by clicking on it
![mysite](img/day1/mysite.png)
11. Right click on `mysite` and click "New Folder". Name it `templates`
![templates](img/day1/templates.gif)
12. Right click on `templates` and click "New Folder". Name it `mysite`
![mysitetemplate](img/day1/mysitetemplates.gif)
13. Right click on the `mysite` folder inside `templates` and click "New File". Name it `index.html`
![index](img/day1/index.gif)
14. Open `index.html` by clicking on it
15. Add the following to index.html
```html
<!DOCTYPE html>
<body>
{{ data }}
</body>
</html>
```
![indexdata](img/day1/indexdata.png)
16. Save with ++ctrl++ + S
17. Open `views.py` by clicking on it
18. In views.py under line 3 add the following:
```python
def index(request):
return render(
request,
"mysite/index.html",
{"data": "hello"}
)
```
![defindex](img/day1/defindex.png)
19. Save with ++ctrl++ + S
20. Right click on `mysite` and click "New File". Name it `urls.py`
![createurls](img/day1/createurls.gif)
21. Add the following to urls.py:
```python
from django.urls import path
from . import views
urlpatterns = [
path('', views.index),
]
```
![indexpath](img/day1/indexpath.png)
22. Save with ++ctrl++ + S
23. In the terminal type `python manage.py runserver`
![runserver](img/day1/runserver.gif)
24. In your browser navigate to <http://localhost:8000>
![hello](img/day1/hello.gif)
You've now passed python data to a browser! We'll explore what this really means in Day 2.

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
docs/img/day0/close_extension.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 KiB

BIN
docs/img/day0/close_welcome.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 918 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

BIN
docs/img/day0/extension.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

BIN
docs/img/day0/git_link.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 MiB

BIN
docs/img/day0/install_python.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

BIN
docs/img/day0/install_success.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
docs/img/day0/kill_terminal.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
docs/img/day0/runserver.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

BIN
docs/img/day0/search_python.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

BIN
docs/img/day0/select_docs.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 KiB

BIN
docs/img/day0/venv_mac.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 725 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

BIN
docs/img/day1/add_file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

BIN
docs/img/day1/config.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 KiB

BIN
docs/img/day1/def_ph.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

BIN
docs/img/day1/defindex.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

BIN
docs/img/day1/hello.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

BIN
docs/img/day1/in_order.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 KiB

BIN
docs/img/day1/include.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

BIN
docs/img/day1/indent_hw.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

BIN
docs/img/day1/index.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 KiB

BIN
docs/img/day1/indexdata.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

BIN
docs/img/day1/indexpath.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

BIN
docs/img/day1/mysite.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 KiB

BIN
docs/img/day1/name_file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

BIN
docs/img/day1/open_file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

BIN
docs/img/day1/print_gb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
docs/img/day1/run_hw.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
docs/img/day1/runserver.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

BIN
docs/img/day1/startapp.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

BIN
docs/img/day1/templates.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 KiB

BIN
docs/img/day1/type_hw.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

BIN
docs/img/day1/urlspy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

16
docs/index.md Normal file
View File

@@ -0,0 +1,16 @@
# Welcome to Project Oriented Java 2020
## Days
### [Day 0](day0.md): Installation requirements
- Install Git
- Install Java
- Install BlueJ
- Create a projects folder
### [Day 1](day1.md): Java basics
- Java in the command-line
- A Java Program
- The Java Compiler