├── .gitignore
├── LICENSE
├── README.md
├── about
└── README.md
├── assignments
├── README.md
├── cheese-mvc-persistent
│ └── README.md
├── images
│ ├── cheryl.jpg
│ ├── eliot.jpg
│ ├── task-list-mvc.png
│ └── task-list-oo.png
├── techjobs-console
│ └── README.md
├── techjobs-mvc
│ └── README.md
├── techjobs-oo
│ └── README.md
└── techjobs-persistent
│ └── README.md
├── class-prep
├── 1
│ ├── README.md
│ ├── exercises.md
│ ├── images
│ │ ├── nameClass.png
│ │ ├── namePackage.png
│ │ ├── newClass.png
│ │ ├── newClassCreated.png
│ │ └── newPackage.png
│ └── setup.md
├── 2
│ ├── README.md
│ └── exercises.md
├── 3
│ └── README.md
├── 4
│ ├── README.md
│ └── exercises.md
├── 5
│ ├── README.md
│ └── exercises.md
├── 6
│ ├── README.md
│ └── exercises.md
├── 7
│ ├── README.md
│ └── exercises.md
├── 8
│ ├── README.md
│ └── exercises.md
├── 9
│ ├── README.md
│ └── exercises.md
├── 10
│ └── README.md
├── 11
│ ├── README.md
│ └── exercises.md
├── 12
│ ├── README.md
│ ├── images
│ │ ├── mamp-add-user.png
│ │ └── mamp-user-accounts.png
│ └── setup.md
├── 13
│ └── README.md
├── 14
│ └── README.md
└── README.md
├── classes
└── README.md
├── couscous.yml
├── ed-splash-1.png
├── glossary
└── README.md
├── issues
└── README.md
├── java4python
├── README.md
├── class-diagrams
│ ├── README.md
│ ├── class-diagram-java.png
│ ├── inheritance-cat.png
│ └── relationships.png
├── classes-and-objects-encapsulating-behavior
│ ├── README.md
│ ├── equality.png
│ └── identity.png
├── classes-and-objects-encapsulating-data
│ └── README.md
├── classes-and-objects-inheritance
│ ├── README.md
│ ├── inheritance-basic.png
│ ├── inheritance-tree.png
│ └── inheritance.png
├── classes-and-objects-interfaces
│ └── README.md
├── control-flow
│ └── README.md
├── data-structures-and-collections
│ └── README.md
├── data-types
│ ├── README.md
│ └── references.png
├── introduction-to-classes-and-objects
│ └── README.md
├── introduction
│ └── README.md
└── naming-conventions
│ └── README.md
├── objectives
└── README.md
├── resources
└── README.md
├── studios
├── README.md
├── area
│ └── README.md
├── bonjour-spring
│ ├── README.md
│ └── form.png
├── cheese-mvc-persistent
│ ├── README.md
│ ├── images
│ │ ├── home-footer-nav.png
│ │ └── main-nav.png
│ ├── many-to-many
│ │ └── README.md
│ ├── one-to-many
│ │ └── README.md
│ └── single-class-persistence
│ │ └── README.md
├── cheese-mvc
│ └── README.md
├── counting-characters
│ └── README.md
├── mvc-design
│ └── README.md
├── quiz-time
│ └── README.md
├── restaurant-menu-continued
│ └── README.md
├── restaurant-menu
│ └── README.md
├── sorting-cities
│ └── README.md
├── user-signup-continued
│ └── README.md
└── user-signup
│ └── README.md
└── videos
├── README.md
├── debugging-in-intellij
└── README.md
├── intro-to-intellij
└── README.md
├── intro-to-orm
└── README.md
├── intro-to-spring-boot-controllers
├── README.md
└── images
│ └── windowsBootRun.png
├── intro-to-spring-boot-enums
└── README.md
├── intro-to-spring-boot-model-validation
└── README.md
├── intro-to-spring-boot-models-1
└── README.md
├── intro-to-spring-boot-models-2
└── README.md
├── intro-to-spring-boot-persistence-1
└── README.md
├── intro-to-spring-boot-persistence-2
└── README.md
├── intro-to-spring-boot-persistence-3
└── README.md
├── intro-to-spring-boot-persistence-4
└── README.md
├── intro-to-spring-boot-routes
└── README.md
├── intro-to-spring-boot-views-1
└── README.md
├── intro-to-spring-boot-views-2
└── README.md
├── intro-to-spring-boot-views-3
└── README.md
├── java-skill-track-overview
└── README.md
├── many-to-many-relationships
└── README.md
└── using-git-in-intellij
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .couscous
2 | .DS_Store
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Couscous
2 |
3 | Copyright (C) Matthieu Napoli
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6 | associated documentation files (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9 | subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all copies or substantial
12 | portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Skill Track: Java Back-End"
3 | layout: home
4 | ---
5 |
--------------------------------------------------------------------------------
/about/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: About This Unit
3 | ---
4 |
5 | This skill-track is an introduction to back-end Java development.
6 |
7 | ## Synopsis
8 |
9 | The Java track covers the essentials of object-oriented Java development, along with portions of the Spring framework.
10 |
11 | Java is one of the more prominent object-oriented languages, and is widely used by professional programmers. You learned a bit about classes and objects as we completed Unit 1, but we'll dive much deeper this time. In addition to creating classes to serve as blueprints for objects, we'll look at the many ways that classes and objects can be used to create robust and flexible programs.
12 |
13 | After covering object-oriented concepts, we'll turn to [Spring](https://projects.spring.io/spring-framework/). Spring is a Java framework that has several large components. We will focus primarily on the Spring MVC component, and, more precisely, Spring Boot. Spring Boot is used to build MVC web applications in Java, including all of the categories of functionality that we saw in Unit 2: templating, database integration, routing, etc.
14 |
15 | Once you complete these classes, you will be well equipped to create a final project!
16 |
17 | ## Topics
18 |
19 | ### Java and Object-oriented Programming
20 |
21 | * **Intro to Java**: Characteristics of the Java language, and procedural Java syntax
22 | * **Objects and Classes**: Objects are the basis of everything in Java. These powerful constructs have a wide range of uses.
23 | * **Unit Tests** are an important piece of any program. We don't know if something works unless we test it!
24 | * **Inheritance, Polymorphism and Interfaces** are useful for leveraging common behaviors and functionality across your classes.
25 | * **Exceptions** are used to inform users of invalid inputs or unexpected behaviors.
26 | * **More!** There are a lot of nuances to Java. We'll cover a few of these in addition to what's above.
27 |
28 | ### Spring Boot
29 |
30 | * **Dependency injection** is a technique that allows some of our objects to be created and managed by Spring. It adds flexibility to our programs, and will be an essential part of Spring Boot.
31 | * **Spring Boot** is a special version of Spring MVC that will allow us to easily create full-featured web applications.
32 | * **Templates** As in Unit 2, we'll use templates to display the views of our web apps.
33 | * **Persistence** We'll look at how to set up classes so that Spring can manage storing and retrieving them from a database.
34 |
--------------------------------------------------------------------------------
/assignments/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Assignments
3 | currentMenu: assignments
4 | ---
5 |
6 | ## How to Submit
7 |
8 | The process for submitting your work is always the same:
9 |
10 | 1. Finish the assignment.
11 | 2. `commit` and `push` your work to a repository on your GitHub profile.
12 | 3. Find the corresponding assignment on [learn.launchcode.org](https://learn.launchcode.org) and enter the GitHub URL for your project.
13 | 4. Find a TF and demo your project for them.
14 |
15 | ## TechJobs (Console Edition)
16 |
17 | 🐘 *Large Assignment*
18 |
19 | [Work on TechJobs (Console Edition)](techjobs-console/)
20 |
21 | ## TechJobs (MVC Edition)
22 |
23 | 🐘 *Large Assignment*
24 |
25 | [Work on TechJobs (MVC Edition)](techjobs-mvc/)
26 |
27 | ## TechJobs (Object-Oriented Edition)
28 |
29 | 🐘 *Large Assignment*
30 |
31 | [Work on TechJobs (Object-Oriented Edition)](techjobs-oo/)
32 |
33 | ## Cheese MVC Persistent
34 |
35 | 🐘 *Large Assignment*
36 |
37 | [Work on Cheese MVC Persistent](cheese-mvc-persistent/)
38 |
--------------------------------------------------------------------------------
/assignments/cheese-mvc-persistent/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 'Assignment: Cheese MVC Persistent'
3 | currentMenu: assignments
4 | ---
5 |
6 | This is your final assignment of the unit. Congrats for making it this far! You're almost to the end...
7 |
8 | This assignment is a bit different from previous assignments. It's structured as a guided walkthrough. You'll be writing code step-by-step with our guidance.
9 |
10 | ## Learning Objectives
11 |
12 | - Configure an individual class to be managed by Spring Data
13 | - Configure a one-to-many relationship to be managed by Spring Data
14 | - Configure a many-to-many relationship to be managed by Spring Data
15 |
16 | ## Your Tasks
17 |
18 | You will work with the `cheese-mvc` application to add ORM functionality by using Spring Data. Follow the tutorials on the [CheeseMVC Persistent studio page](../../studios/cheese-mvc-persistent/). Complete all three parts.
19 |
20 | You will have some time to work on these items in class, but you are ultimately responsible for completing all three sections on your own by the due date.
21 |
22 | ### How to Submit
23 |
24 | To turn in your assignment and get credit, follow the [submission instructions][submission-instructions].
25 |
26 | [submission-instructions]: ../
27 |
28 | ## Bonus Missions
29 |
30 | Bonus missions are outlined in parts 2 and 3 of the studio. Refer to those pages for details.
31 |
--------------------------------------------------------------------------------
/assignments/images/cheryl.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/assignments/images/cheryl.jpg
--------------------------------------------------------------------------------
/assignments/images/eliot.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/assignments/images/eliot.jpg
--------------------------------------------------------------------------------
/assignments/images/task-list-mvc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/assignments/images/task-list-mvc.png
--------------------------------------------------------------------------------
/assignments/images/task-list-oo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/assignments/images/task-list-oo.png
--------------------------------------------------------------------------------
/assignments/techjobs-persistent/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 'Assignment: TechJobs (Persistent Edition)'
3 | currentMenu: assignments
4 | ---
5 |
6 | *Coming soon...*
7 |
--------------------------------------------------------------------------------
/class-prep/1/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 1 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Watch | Video | [Java Skill Track Overview](https://youtu.be/M1niptdxtIM) | Learn about the content and structure of this unit.
9 | Do | Interactive Course | [Udacity Intro to Java](https://classroom.udacity.com/courses/ud282/lessons/8186340458/concepts/05ff9d5e-8ce4-4a64-8a32-4650f50e7acf#) | *Do only Lesson 5, "Introduction" through "Hello World in IntelliJ"*. These lessons provide a great introduction to how Java programs run, and how to set up the tools you need to work with Java applications. This portion of Lesson 5 is independent from Lessons 1-4, so don't worry about skipping the earlier lessons. However, **be sure to do all of the setup work that this lesson guides you through.**
10 | Do | Instructions | [Initial Setup](setup.html) | Set up IntelliJ with the Git repository that you'll be working with for the start of this unit.
11 | Read | Lesson | [Java For Python Programmers](../../java4python) | **Read lesson 1 ("Introduction") and lesson 2 ("Data Types").** This set of lessons introduces Java concepts by drawing parallels to the Python skills you've already gained.
12 | Do | Exercises | [Class 1 Prep Exercises](exercises.html) | Get some practice with the concepts you've just learned
13 |
--------------------------------------------------------------------------------
/class-prep/1/exercises.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 1 Prep Exercises
3 | currentMenu: classes
4 | ---
5 |
6 | ## Instructions
7 |
8 | Work on these exercises in the `java-exercises` project, creating a new class for each. You may name the classes whatever you like, but use proper [Java naming conventions](../../java4python/naming-conventions/) and make sure that the file name matches the class name!
9 |
10 | Here is how to create a new package to store these exercises, and how to create new classes within this package:
11 |
12 | 1. Click on the folder `src` in the Project pane, then right click and select "New" and then select "Package".
13 |
14 | 
15 |
16 | 2. Name the package "exercises".
17 |
18 | 
19 |
20 | 3. Then click on the newly-created folder `exercises` and right click to select "New" and then select "Class".
21 |
22 | 
23 |
24 | 4. Name the package what you will name your class (for example, in the 4th exercise below, you might name the class `Alice`).
25 | **Note:** You will be asked whether you want to add this file to Git. Press the "Yes" button.
26 |
27 | 
28 |
29 | 5. The new class is now created! You can proceed to write code within it. (Don't forget to write the `main` method!)
30 |
31 | 
32 |
33 | ## Exercises
34 |
35 | 1. **Input/output**: Modify your "Hello, World" program to prompt the user for their name, and greet them by name.
36 | 1. **Numeric types**: Write a program to calculate the area of a rectangle and print the answer to the console. You should prompt the user for the dimensions. (What data types should the dimensions be?)
37 | 2. **Numeric types**: Write a program that asks a user for the number of miles they have driven and the amount of gas they've consumed (in gallons), and print their miles-per-gallon.
38 | 3. **Strings**: The first sentence of *Alice's Adventures in Wonderland* is below. Store this sentence in a string, and then prompt the user for a term to search for within this string. Print whether or not the search term was found. See if you can make the search case-insensitive, so that searching for "alice", for example, prints `true`.
39 | ```nohighlight
40 | Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'
41 | ```
42 |
--------------------------------------------------------------------------------
/class-prep/1/images/nameClass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/class-prep/1/images/nameClass.png
--------------------------------------------------------------------------------
/class-prep/1/images/namePackage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/class-prep/1/images/namePackage.png
--------------------------------------------------------------------------------
/class-prep/1/images/newClass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/class-prep/1/images/newClass.png
--------------------------------------------------------------------------------
/class-prep/1/images/newClassCreated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/class-prep/1/images/newClassCreated.png
--------------------------------------------------------------------------------
/class-prep/1/images/newPackage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/class-prep/1/images/newPackage.png
--------------------------------------------------------------------------------
/class-prep/1/setup.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Initial Setup
3 | currentMenu: classes
4 | ---
5 |
6 | The steps here will walk you through setting up a repository that you'll use to study example code, work on studios, and complete your first assignment of this unit.
7 |
8 | - Create a copy of the `LaunchCodeEducation / java-exercises` repo on GitHub by visiting the [repository page](https://github.com/LaunchCodeEducation/java-exercises) and clicking on the *Fork* button below your profile picture at the top right.
9 | - Open IntelliJ.
10 | - If the app opens up to an existing project, select *IntelliJ > Preferences > Appearance & Behavior > System Settings* and uncheck *Reopen last project on startup*. (For Windows users: *File > Settings > Appearance & Behavior > System Settings*.) Close and Reopen IntelliJ.
11 | - From the "Welcome to IntelliJ" dialog, select *Check out from Version Control > GitHub*
12 | - The first time you use GitHub within IntelliJ you'll have to configure IntelliJ to use your GitHub Account. We recommend taking the extra step of authenticating using a token. This takes only one brief extra step, and will prevent you from having to update IntelliJ settings if you ever change your GitHub password.
13 | - From the project selection dialog, select the `java-exercises` repository, along with an appropriate source destination directory (i.e. a folder where you've stored other projects for this class).
14 | - When asked "Would you like to create and IDEA project..." select *Yes*, and then accept all of the default options that are presented.
15 |
16 | With that, you're ready to go!
17 |
18 | Here's a video walking through the last 4 steps above:
19 |
20 |
21 |
22 | ## Troubleshooting
23 |
24 | ### ClassNotFoundException
25 |
26 | If you experience `java.lang.ClassNotFoundException` when trying to run code after setting up the project, follow these steps:
27 | 1. Select *File > Close Project*
28 | 2. From the IntelliJ modal window, click the *X* next to `java-exercises` in the left-hand pane.
29 | 3. From the same modal window, select *Import Project* from the right-hand pane.
30 | 4. Follow the steps that IntelliJ guides you through, accepting all defaults. When prompted to overwrite IntelliJ settings files, you confirm that you want to do so.
31 |
--------------------------------------------------------------------------------
/class-prep/10/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 10 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Read | Assignment | [TechJobs (Object-Oriented Edition)](../../assignments/techjobs-oo/) | This assignment is a big one, with lots of ideas coming together. We'll spend some time in class discussing the ideas, so be sure to read the assignment details and look at the starter code before coming to class.
9 | Read | Tutorial | [Lesson: Exceptions](https://docs.oracle.com/javase/tutorial/essential/exceptions/) | Read this set of lessons on exceptions in Java. Use the **Questions** section to confirm your learning, optionally also working on the **Exercises**. The language in these articles is slightly more advanced than what we've been used to, but as we near the end of the course we want you to become more comfortable reading documentation.
10 | Read | Article | Exceptions Best Practices | Use exceptions like a pro!
11 |
--------------------------------------------------------------------------------
/class-prep/11/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 11 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Read | *Java For Python Programmers* | [Classes and Objects: Interfaces](../../java4python/classes-and-objects-interfaces/) | Learn about interfaces and polymorphism.
9 | Read | Documentation | [Comparator.compare Method](http://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html#compare-T-T-) | Read about the `compare` method for the `Comparator` interface, and how it is intended to work. We'll use this in the studio for the next class.
10 | Do | Exercises | [Class 11 Prep Exercises](exercises.html) | Exercise the concepts that you've just learned.
11 |
--------------------------------------------------------------------------------
/class-prep/11/exercises.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 11 Prep Exercises
3 | currentMenu: classes
4 | ---
5 |
6 | We've learned that `ArrayList` implements both `List` and `Iterable`. In fact, `List` extends `Iterable`, which means that `List` includes all of the contracted methods that `Iterable` does. Check out the documentation for [List<T>](https://docs.oracle.com/javase/8/docs/api/java/util/List.html0) and [Iterable<T>](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html) to confirm for yourself!
7 |
8 | Open up your `techjobs-mvc` solution. Within `ListController` and `SearchController`, change every local variable that's declared to be of type `ArrayList` to be either a `List` or an `Iterable`, using the least restrictive type as possible. In other words, if you only need to loop over the collection, use `Iterable`, but if you also need to access elements of the collection by index -- as in, `var item = items.get(0)` -- then use `List`. Be sure to look at the templates to see how collections being passed into the templates are used. Also be sure to test your code after making these changes!
9 |
--------------------------------------------------------------------------------
/class-prep/12/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 12 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Setup | Article | [Database and Hibernate Setup](setup.html) | Follow the instructions to setup a local database and enable the Hibernate ORM framework for your `cheese-mvc` project.
9 | Watch | Lesson | [Intro to Object-Relational Mapping](../../videos/intro-to-orm/) | Review relational data and object-relational mapping
10 | Watch / Code Along | Video | [Intro to Spring Boot: Persisting Objects with JPA](../../videos/intro-to-spring-boot-persistence-1/) | Learn how to store objects in a MySQL database in Spring Boot using JPA and Hibernate.
11 | Read | Cheatsheet | [Spring Boot Persistence](https://github.com/LaunchCodeEducation/cheatsheets/blob/master/spring-persistence/) | Review this cheatsheet on annotating persistent classes
12 | Watch / Code Along | Video | [Intro to Spring Boot: Persisting One-to-Many Relationships](../../videos/intro-to-spring-boot-persistence-2/) | Learn how to work with relationships between objects when using ORM.
13 |
--------------------------------------------------------------------------------
/class-prep/12/images/mamp-add-user.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/class-prep/12/images/mamp-add-user.png
--------------------------------------------------------------------------------
/class-prep/12/images/mamp-user-accounts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LaunchCodeEducation/skills-back-end-java/2272727d7d702c65f218cba7387a28011a94433f/class-prep/12/images/mamp-user-accounts.png
--------------------------------------------------------------------------------
/class-prep/12/setup.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Database and Hibernate Setup
3 | currentMenu: classes
4 | ---
5 |
6 | This article walks you through the steps needed to setup a Spring Boot application to use MySQL for local development.
7 |
8 | ## Install MAMP
9 |
10 | MAMP is a suite of tools useful for developers. The acronym MAMP stands for Mac / Apache / MySQL / PHP, and despite the first term, there is a version for Windows as well. While we won't use Apache and PHP directly, they'll provide us with an interface to work with our MySQL server, called *phpMyAdmin*.
11 |
12 | If you didn't already install MAMP in Unit 2, [install MAMP for your system](https://www.mamp.info/en/). *Do not* install MAMP Pro, which is not free.
13 |
14 |
17 |
18 | ## Setting Up the Database
19 |
20 | Start up MAMP. From the launcher window, select *Start Servers*. Once that button has turned green, choose *Open Start Page*. From the page that opens up in your browser, select *Tools > phpMyAdmin*.
21 |
22 | Select *User Accounts*.
23 |
24 | 
25 |
26 | Fill out the resulting form with info for your application. A good pattern to follow is that you should have a different user for each application, and the username should match the name of your application.
27 |
28 | Set the *Host name* field to *Local* and set a password. For local development, it's acceptable to use a simple password. Just be sure that you don't use the same password on a production database if you deploy your application!
29 |
30 |
33 |
34 | And be sure to check the first checkbox under *Database for user account*. If you don't do this, you'll have to create a database and set permissions manually.
35 |
36 | 
37 |
38 | ## Configuring Your Spring Boot App
39 |
40 | These steps will need to be carried out for each application that you want to make work with a database. In the case of our `cheese-mvc` application, the following lines and files will already be included in the `video-jpa-start` branch of the LaunchCodeEducation's `cheese-mvc` [repository](https://github.com/LaunchCodeEducation/cheese-mvc/tree/video-jpa-start). This branch has the code that we will start working from during our first `cheese-mvc` related video lesson for this class. But if you want to keep using the code that you have been building while coding along with the videos, then be sure to add the lines and files below.
41 |
42 | ### Dependencies
43 |
44 | Make sure these lines are in the `dependencies` section of your `build.gradle`:
45 | ```nohighlight
46 | compile('org.springframework.boot:spring-boot-starter-data-jpa')
47 | compile('mysql:mysql-connector-java')
48 | ```
49 |
50 | The `spring-boot-starter-data-jpa` artifact includes the Hibernate ORM framework. We won't talk explicitly about Hibernate very much, since we won't need to work with it directly in most situations. We'll primarily work with Java Persistence API annotations, but you should know that Hibernate provides the implementation for most of these behaviors behind the scenes. In settings other than Spring Boot, you'd likely work with Hibernate much more directly.
51 |
52 | ### `application.properties`
53 |
54 | The database connection needs to be configured via `src/main/resources/application.properties`. Make sure these lines are in that file:
55 |
56 | ```nohighlight
57 | # Database connection settings
58 | spring.datasource.url=jdbc:mysql://localhost:8889/cheese-mvc
59 | spring.datasource.username=cheese-mvc
60 | spring.datasource.password=cheese
61 |
62 | # Specify the DBMS
63 | spring.jpa.database = MYSQL
64 |
65 | # Show or not log for each sql query
66 | spring.jpa.show-sql = false
67 |
68 | # Hibernate ddl auto (create, create-drop, update)
69 | spring.jpa.hibernate.ddl-auto = update
70 |
71 | # Use spring.jpa.properties.* for Hibernate native properties (the prefix is
72 | # stripped before adding them to the entity manager)
73 | spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
74 | ```
75 |
76 |
85 |
86 | The username and password, along with the database name in the datasource URL, *should match the values you used when creating your database* in MAMP. We recommended using "cheese-mvc" and "cheese" respectively.
87 |
88 |
91 |
92 | These properties are discussed in more depth in the [Spring Boot Persistence cheatsheet](https://github.com/LaunchCodeEducation/cheatsheets/blob/master/spring-persistence/).
93 |
94 | Now your app is configured to use Hibernate with MySQL. You'll need to make some additions and changes to your Java code to specify how object should be mapped into the database. This is the topic of upcoming lessons.
95 |
--------------------------------------------------------------------------------
/class-prep/13/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 13 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Watch | Lesson | [Many-to-Many Relationships](../../videos/many-to-many-relationships/) | Learn about how many-to-many relationships are handled by ORM frameworks
9 | Watch | Lesson | [Intro to Spring Boot: Persisting Many-to-Many Relationships (Part 1)](../../videos/intro-to-spring-boot-persistence-3/) | Build model classes that enable persistent many-to-many relationships
10 | Watch | Lesson | [Intro to Spring Boot: Persisting Many-to-Many Relationships (Part 2)](../../videos/intro-to-spring-boot-persistence-4/) | Work with many-to-many relationships in the controller and view layers
11 |
--------------------------------------------------------------------------------
/class-prep/14/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 14 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | There is no additional prep work for the last class meeting. Work on your final assignment. And celebrate making it to the end of the class! Congratulations!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/class-prep/2/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 2 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Read | Java For Python Programmers | [Control Flow](../../java4python/control-flow/) | Learn about conditionals and loops in Java
9 | Read | Java For Python Programmers | [Collections](../../java4python/data-structures-and-collections/) | Learn about collections in Java
10 | Do | Exercises | [Class 2 Prep Exercises](exercises.html) | Get some practice with the concepts you've just learned
11 |
--------------------------------------------------------------------------------
/class-prep/2/exercises.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 2 Prep Exercises
3 | currentMenu: classes
4 | ---
5 |
6 | Work on these exercises in the `java-exercises` project, creating a new class for each. You may name the classes whatever you like, but use proper [Java naming conventions](../../java4python/naming-conventions/).
7 |
8 | 1. **ArrayList**: Write a static method to find the sum of all the even numbers in a list. Within `main`, create a list with at least 10 integers and call your method on the list.
9 | 2. **ArrayList and Strings**: Write a static method to print out each word in a list that has exactly 5 letters.
10 | 3. **Arrays**: Create and initialize an array with the following values in a single line: 1, 1, 2, 3, 5, 8. Then loop through the array and print out each value.
11 | 3. **HashMap**: Make a program similar to `GradebookHashMap`, but which takes in students names and ID numbers (as integers) instead of names and grades. In this case, however, the keys should be integers (the IDs) and the values should be strings (the names). Modify the roster printing code accordingly.
12 |
--------------------------------------------------------------------------------
/class-prep/3/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 3 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Watch | Video | [Intro to IntelliJ](../../videos/intro-to-intellij/) | Learn about some of the ways that IntelliJ makes your life as a programmer easier
9 | Watch | Video | [Debugging in IntelliJ](../../videos/debugging-in-intellij/) | Learn how to use IntelliJ's debugger
10 | Watch | Video | [Using Git in IntelliJ](../../videos/using-git-in-intellij/) | Learn about using Git within IntelliJ's interface, and connecting to remote GitHub repositories
11 | Watch / Follow Along | Video | [Intro to Spring Boot: Controllers](../../videos/intro-to-spring-boot-controllers/) | An introduction to the Spring Boot framework, and how to set up simple controllers. **NOTE:** You should code along with this video. We will continue to build on this application, and you'll use your Hello Spring app in-class during studios.
12 | Watch / Follow Along | Video | [Intro to Spring Boot: Routes](../../videos/intro-to-spring-boot-routes/) | An introduction to routing in the Spring Boot framework. **NOTE:** You should code along with this video. We will continue to build on this application, and you'll use your Hello Spring app in-class during studios.
13 | Read | **Bonus Mission** | [Java Quickstart with Gradle](https://docs.gradle.org/current/userguide/tutorial_java_projects.html) | This overview goes more in-depth about what Gradle does for Java projects. Much of the jargon will be new, but you'll still get an idea of what goes on behind the scenes when you use Gradle in your project.
14 |
--------------------------------------------------------------------------------
/class-prep/4/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 4 Prep
3 | currentMenu: classes
4 | ---
5 |
6 |
9 |
10 | Task | Resource Type | Link | Instructions
11 | |----|---------------|------|-------------|
12 | Watch / Follow Along | Video | [Intro to Spring Boot: Views (Part 1)](../../videos/intro-to-spring-boot-views-1/) | Integrate Thymeleaf templates into Spring Boot
13 | Watch / Follow Along | Video | [Intro to Spring Boot: Views (Part 2)](../../videos/intro-to-spring-boot-views-2/) | Introduce Thymeleaf syntax, and pass data from views to controllers
14 | Watch / Follow Along | Video | [Intro to Spring Boot: Views (Part 3)](../../videos/intro-to-spring-boot-views-3/) | Learn some ways to reduce boilerplate template code, include static resources (like CSS and JS files), and to make your life a bit easier using Thymeleaf in IntelliJ
15 | Do | Exercises | [Class 4 Prep Exercises](exercises.html) | Get some practice with the concepts you've just learned
16 |
--------------------------------------------------------------------------------
/class-prep/4/exercises.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 4 Prep Exercises
3 | currentMenu: classes
4 | ---
5 |
6 | Get some hands-on practice with views in MVC. Work on these exercises within the `CheeseMVC` app that was created during our [Intro to Spring Boot: Views](README.md) video lessons.
7 |
8 | 1. Add a `description` field to the application. This will involve:
9 | - Modifying the static `cheeses` list to be a `HashMap`\* object with key/value pairs that correspond to the name/description of the cheese.
10 | - Adding a new form input field in `cheese/add.html` to allow for submission of the description.
11 | - Modifying the `processAddCheeseForm` method to insert the name and description of the new cheese into the `cheeses` HashMap. \*\*
12 | - Displaying the description field in the `cheese/index.html` view template. \*\*\*
13 | 2. Add some styles to `resources/static/css/styles.css` to improve the look and feel of your application. We added stylesheets to our application in [Intro to Spring Boot: Views (Part 3)](../../videos/intro-to-spring-boot-views-3/)
14 | 3. Answer the following questions:
15 | - What does it mean that "Thymeleaf templates are **natural** templates"?
16 | - What are the benefits of using a `fragments.html` base template?
17 | - Describe some best practices involving template organization and annotating request paths. (Hint: these are covered in [Intro to Spring Boot: Views (Part 1)](../../videos/intro-to-spring-boot-views-1/).)
18 |
19 | \* You can review `HashMap` syntax [here](../../java4python/data-structures-and-collections/#keyvalue-data-hashmaps).
20 | \*\* To use multiple `@RequestParam`s, use this syntax:
21 | ```Java
22 | public String multiParamExample (@RequestParam String one, @RequestParam String two)
23 | ```
24 | \*\*\* When iterating over a map, the components of each item can be accessed using `.key` and `.value`:
25 | ```HTML
26 |
27 |
Key
28 |
Value
29 |
30 | ```
31 | Also, you may find Thymeleaf syntax like the following useful:
32 | ```HTML
33 |
34 | ```
35 | Where `oneThing` and `anotherThing` are data passed in from the controller. For example, if the value of `oneThing` were "This rocks" and the value of `anotherThing` were "Doesn't it?", the above would render in the browser as:
36 | ```nohighlight
37 | This rocks! Doesn't it?
38 | ```
39 |
40 | Don't forget to use this [Thymeleaf Cheatsheet](https://github.com/LaunchCodeEducation/cheatsheets/tree/master/thymeleaf) if you need a reference!
41 |
--------------------------------------------------------------------------------
/class-prep/5/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 5 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Read | Java For Python Programmers | [Introduction to Classes and Objects](../../java4python/introduction-to-classes-and-objects/) | At long last, we start our exploration of object-oriented programming in Java!
9 | Read | Java For Python Programmers | [Classes and Objects: Encapsulating Data](../../java4python/classes-and-objects-encapsulating-data/) | Learn about how we define and configure fields within classes
10 | Do | Exercises | [Class 5 Prep Exercises](exercises.html) | Exercise the concepts that you've just learned
11 |
--------------------------------------------------------------------------------
/class-prep/5/exercises.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 5 Prep Exercises
3 | currentMenu: classes
4 | ---
5 |
6 | 1. **Class Design:** In IntelliJ, create a new package `school` in the `java-exercises` project. Add the class `Student` that was discussed in [the reading for this class][encapsulating-data] to this new package. Add all getters and setters. Think about the access level each should have, and reduce the access level of at least one setter to less than public. Make sure you can defend your reasoning in words.
7 | 1. **More class design:** In the `school` package, create a class `Course` with at least three fields. Before diving into IntelliJ, use pen and paper to work through what these might be, including the data types, access levels, and whether it makes sense for any of them to be `static` or `final`. At least one of your fields should be an `ArrayList` or `HashMap`, and you should use your `Student` class.
8 | 1. **More Cheese:** More CheeseMvc, that is. Fire up this Spring Boot application, and create a new package within `org.launchcode.cheesemvc` named `models`. (Your specific package name may be slightly different if you used a different project name. Put `models` _next to_ your `controllers` package.) Within that package, create a `Cheese` class that has `name` and `description` properties, along with getters and setters. Refactor the `CheeseController` to use `Cheese` objects rather than the strings that were used previously. You'll need to update your views as well.
9 | 1. **Review:** With a pen and paper, write down descriptions of each of the following field types, along with an example of a situation where you might use each: public field, private field, static field, final field. If you get stuck, review the lesson on [encapsulating data][encapsulating-data].
10 |
11 |
12 | [encapsulating-data]: ../../java4python/classes-and-objects-encapsulating-data/
13 |
--------------------------------------------------------------------------------
/class-prep/6/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 6 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Read | *Java For Python Programmers* | [Classes and Object: Encapsulating Behavior](../../java4python/classes-and-objects-encapsulating-behavior/) | Learn about how we define and work with methods in our classes
9 | Do | Exercises | [Class 6 Prep Exercises](exercises.html) | Exercise the concepts that you've just learned
10 |
--------------------------------------------------------------------------------
/class-prep/6/exercises.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 6 Prep Exercises
3 | currentMenu: classes
4 | ---
5 |
6 | 1. In your `Student` class, update the code with implementations for `addGrade` and `getGradeLevel` which were sketched out in [Classes and Objects: Encapsulating Behavior](../../java4python/classes-and-objects-encapsulating-behavior/). For the method `addGrade`, you'll need to update the student's GPA. To do this, note that GPA is computed via the formula:
7 | ```nohighlight
8 | gpa = (total quality score) / (total number of credits)
9 | ```
10 | The total quality score is the sum of the quality scores of all classes, and the quality score for a class is found by multiplying the point score (0.0-4.0) by the number of credits. For example, if a student received an A (worth 4 points) in a 3-credit course and a B (worth 3 points) in a 4-credit course, their quality score would be: 4.0 \* 3 + 3.0 \* 4 = 24. And their GPA would then be 24 / 7 = 3.43.
11 |
12 | To update the GPA, you'll need to update the quality score. You can compute the existing quality score by calculating `gpa * numberOfCredits`. Then update the quality score and `numberOfCredits`, and compute the new GPA with the new numbers.
13 |
14 | In `getGradeLevel` you will need to determine the level of the student based on the number of credits: freshman (0-29 credits), sophomore (30-59 credits), junior (60-89 credits), or senior (90+ credits).
15 | 1. Add custom `equals()` and `toString()` methods to the `Student` class.
16 | 2. Add custom `equals()` and `toString()` methods to the `Course` class which you started in the [exercises for class 5](../5/exercises.html).
17 |
--------------------------------------------------------------------------------
/class-prep/7/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 7 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Read | *Java For Python Programmers* | [Classes and Object: Inheritance](../../java4python/classes-and-objects-inheritance/) | Learn about inheritance and class extensions
9 | Read | *Java For Python Programmers* | [Class Diagrams](../../java4python/class-diagrams/) | Learn about using simple diagrams to design your classes
10 | Do | Exercises | [Class 7 Prep Exercises](exercises.html) | Exercise the concepts that you've just learned
11 |
--------------------------------------------------------------------------------
/class-prep/7/exercises.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 7 Prep Exercises
3 | currentMenu: classes
4 | ---
5 |
6 | - **Class design:** Pick one or more of the following groups of classes, and diagram your design for each (including methods and properties). Be sure to use lines/arrows to indicate inheritance relationships, and to include data and behavior that somebody using your classes would likely want.
7 | - Shape, Square, Rectangle, Circle
8 | - Computer, Desktop, Laptop, SmartPhone
9 | - Student, GraduateStudent, UndergraduateStudent
10 | - **Class implementation:** For one of the groups of classes above, implement your design and test it in a `Program.java` class. You can create this in your `java-exercises` project.
11 | - **Abstract class design:** Consider the group of classes that you designed. Suppose you had a web program that used these classes, and you needed to assign a unique ID to every object created from one of these classes within the application. In other words, each such class should have an `Id` property, and no two objects created from any of the classes may have the same ID value. Create an abstract class, `AbstractEntity`, that contains the behavior for assigning and accessing such a unique ID for each class that extends it. Add this class to your program above, and add `AbstractEntity` to the class hierarchy in the correct place.
12 |
--------------------------------------------------------------------------------
/class-prep/8/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 8 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Watch / Code Along | Video | [Intro to Spring Boot: Models (Part 1)](../../videos/intro-to-spring-boot-models-1/) | Create a model class to encapsulate data in cheese-mvc
9 | Watch / Code Along | Video | [Intro to Spring Boot: Models (Part 2)](../../videos/intro-to-spring-boot-models-2/) | Create unique identifiers for the model, and extract data management from the controller; learn about model binding
10 | Do | Exercises | [Class 8 Prep Exercises](exercises.html) | Exercise the concepts that you've just learned
11 |
--------------------------------------------------------------------------------
/class-prep/8/exercises.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 8 Prep Exercises
3 | currentMenu: classes
4 | ---
5 |
6 | Add "edit" functionality to the `cheese-mvc` application by following these steps. It assumes that you've added all of the code from both of the [models lessons](../../videos/).
7 |
8 | 1. Stub out two handler methods in `CheeseController`. We'll add code to these in a moment, so just put the method outline in place for now.
9 | - Create a method to display the form with this signature:
10 | ```java
11 | public String displayEditForm(Model model, @PathVariable int cheeseId)
12 | ```
13 | - Create a method to process the form with this signature:
14 | ```java
15 | public String processEditForm(int cheeseId, String name, String description)
16 | ```
17 | 2. Add the necessary annotations to these forms for them to both live at the path `/cheese/edit` (note that we've configured `@RequestMapping` on the controller class already), and so that the first handles `GET` requests, and the second `POST` requests. You'll need to configure the route for `displayEditForm` to include the path variable, so that paths like `/cheese/edit/3` will work.
18 | 3. Create an `edit.html` view template in `resources/templates/cheese`.
19 | 4. Copy the code from `add.html` into `edit.html`. You can copy the entire file contents.
20 | 5. Back in the `displayEditForm` handler, ask `CheeseData` for the object with the given `cheeseId` and put it in the `model`. Return the appropriate template string.
21 | 6. Within the form fields in `edit.html`, get the name and description from the cheese that was passed in via the `model` and set them as the values of the form fields.
22 | 7. Add another input to hold the id of the cheese being edited. This should be hidden from the user:
23 | ```html
24 |
25 | ```
26 | 8. Add a heading at the top of `edit.html` that says "Edit Cheese NAME (id=ID)" where NAME and ID are replaced by the values of the given cheese.
27 | 9. Back in `processEditForm`, query `CheeseData` for the cheese with the given id, and then update its name and description. Redirect the user to the home page.
28 | 10. In `resources/templates/cheese/index.html`, add a link to edit the cheese:
29 | ```html
30 | edit
31 | ```
32 | You can put this link in a third table column, or in one of the existing table cells.
33 | 11. Test your code! With so many changes, it's likely that you made an error somewhere. Be patient, use IntelliJ's debugger, and read your error messages.
34 |
--------------------------------------------------------------------------------
/class-prep/9/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 9 Prep
3 | currentMenu: classes
4 | ---
5 |
6 | Task | Resource Type | Link | Instructions
7 | |----|---------------|------|-------------|
8 | Watch / Code Along | Video | [Intro to Spring Boot: Model Validation](../../videos/intro-to-spring-boot-model-validation/) | Add code to validate your model data
9 | Read | Tutorial | [Enum Types](http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html) | Learn about enum classes in Java
10 | Watch / Code Along | Video | [Intro to Spring Boot: Enums and Selects in Views](../../videos/intro-to-spring-boot-enums/) | Add some more complex functionality to your app by giving users categorial choices via enums
11 | Do | Exercises | [Class 9 Prep Exercises](exercises.html) | Exercise the concepts that you've just learned
12 |
--------------------------------------------------------------------------------
/class-prep/9/exercises.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Class 9 Prep Exercises
3 | currentMenu: classes
4 | ---
5 |
6 | 1. Let's add validation to our `edit` handlers. If you haven't set up edit functionality in your `cheese-mvc` app, you can add it by following the steps in [class 8 prep exercises](../8/exercises.html).
7 |
8 | In the `edit` handler that displays the form, you should already be passing in the `Cheese` object to be edited. This means that we can refactor the form in the `edit.html` template to use `th:object="${cheese}"` and then use `th:field="*{propertyName}"` to help render the inputs. Don't forget to modify the `