Skip to content

Commit a229f1a

Browse files
committed
first commit
0 parents  commit a229f1a

19 files changed

+2241
-0
lines changed

code.md

Lines changed: 1071 additions & 0 deletions
Large diffs are not rendered by default.

exercises.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Exercise 1
2+
3+
Print Only Odd Numbers from the List
4+
5+
# Exercise 2
6+
7+
Print All Courses individually
8+
9+
`List<String> courses = List.of("Spring", "Spring Boot", "API" , "Microservices", "AWS", "PCF","Azure", "Docker", "Kubernetes")`
10+
11+
# Exercise 3
12+
13+
Print Courses Containing the word "Spring"
14+
15+
# Exercise 4
16+
17+
Print Courses Whose Name has atleast 4 letters
18+
19+
# Exercise 5
20+
21+
Print the cubes of odd numbers
22+
23+
# Exercise 6
24+
25+
Print the number of characters in each course name
26+
27+
28+
# Exercise 7
29+
30+
Square every number in a list and find the sum of squares
31+
32+
# Exercise 8
33+
34+
Cube every number in a list and find the sum of cubes
35+
36+
# Exercise 9
37+
38+
Find Sum of Odd Numbers in a list
39+
40+
# Exercise 10
41+
42+
Create a List with Even Numbers Filtered from the Numbers List
43+
44+
# Exercise 11
45+
46+
Create a List with lengths of all course titles.
47+
48+
# Exercise 12
49+
50+
Find Functional Interface behind the second argument of reduce method. Create an implementation for the Functional Interface.
51+
52+
int sum = numbers.stream()
53+
.reduce(0, Integer::sum);
54+
55+
# Exercise 13
56+
57+
Do Behavior Parameterization for the mapping logic.
58+
59+
List<Integer> squaredNumbers = numbers.stream()
60+
.map(x -> x*x)
61+
.collect(Collectors.toList());

file.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Some Text
2+
Some Text that will be saved
3+
A lot of Text Present in here

readme.md

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
# Functional Programming with Java
2+
3+
## Learn Functional Programming with Java using a Hands-on Step by Step Approach
4+
5+
Are you ready to learn about Functional Programming and take the next step in your programming career?
6+
7+
Do you want to join 300,000+ learners having Amazing Learning Experiences with in28Minutes?
8+
9+
Look No Further!
10+
11+
#### Required Tools
12+
- Java 9+
13+
- Eclipse - Oxygen+ - (Embedded Maven From Eclipse)
14+
15+
#### Installing Guides
16+
- [Playlist - Installing Java, Eclipse & Embedded Maven](https://www.youtube.com/playlist?list=PLBBog2r6uMCSmMVTW_QmDLyASBvovyAO3)
17+
18+
#### Troubleshooting Installations
19+
- Eclipse and Embedded Maven
20+
- Troubleshooting Guide - https://github.com/in28minutes/in28minutes-initiatives/tree/master/The-in28Minutes-TroubleshootingGuide-And-FAQ#tip--troubleshooting-embedded-maven-in-eclipse
21+
- PDF - https://github.com/in28minutes/SpringIn28Minutes/blob/master/InstallationGuide-JavaEclipseAndMaven_v2.pdf
22+
- GIT Repository For Installation - https://github.com/in28minutes/getting-started-in-5-steps
23+
24+
## Course Overview
25+
26+
******* Course Overview *******
27+
28+
Architectures are moving towards Microservices and Cloud. Docker makes it easy to containerize your applications and make them cloud ready.
29+
30+
Docker is the No 1 Tool to Containerize your Java Spring Boot Applications. Learning Docker would help you streamline your deployment processes and experiment easily with new frameworks and tools.
31+
32+
In this handson course, we will containerize - create docker images and create containers - for a variety of Spring Boot Applications:
33+
- REST APIs - Hello World and Todo - Jar
34+
- Todo Web Application War
35+
- Full Stack Application with React and Spring Boot
36+
- CCS and CES Microservices
37+
- Eureka Naming Server and Zuul API Gateway
38+
39+
This course would be a perfect first step as an introduction to Docker.
40+
41+
You will be using containerizing a variety of projects created with React (Frontend Framework), Spring Boot (REST API Framework), Spring (Dependency Management), Spring Security (Authentication and Authorization - Basic and JWT), BootStrap (Styling Pages), Maven (dependencies management), Node (npm), Visual Studio Code (TypeScript IDE), Eclipse (Java IDE) and Tomcat Embedded Web Server. We will help you set up each one of these.
42+
43+
## What you'll learn
44+
- You will Learn the Fundamentals of Docker from Zero, no previous experience required
45+
- You will learn the important Docker Concepts - Registry, Repository, Tag, Image, Container and Volumes
46+
- You will learn the important Docker commands
47+
- You will understand the Docker Architecture
48+
- You will create Docker images for 8 Java Spring Boot Projects
49+
- You will learn to use Dockerfile to Automate Building of your Docker Image
50+
- You will learn to use various maven plugins - Dockerfile Spotify Plugin, JIB Plugin and Fabric8 Docker Maven Plugin - to create Docker images
51+
- You will learn to create best practices with creating Docker Images - Improve Caching of Docker Images and create Multi Stage Docker Builds.
52+
- You will Containerize Java Spring Boot Todo Web Application talking with MySQL
53+
- You will Containerize Java Spring Boot React Full Stack Application with Docker
54+
- You will Containerize CCS, CES Microservices, Eureka Naming Server and Zuul API Gateway with Docker and Run them using Docker Compose
55+
- You will learn to run MySQL, RabbitMQ and Zipkin as Docker Containers
56+
- You will learn the basics of Docker Networking - HOST, BRIDGE and NONE
57+
- You will learn to use Docker Compose to Manage Your Containers
58+
- You will learn the basics of Microservices
59+
- You will Join 250,000 Learners having AMAZING LEARNING Experiences with in28Minutes
60+
61+
## Requirements
62+
- You have an attitude to learn while having fun :)
63+
- You have some programming experience with Java, Spring and Spring Boot
64+
- You DO NOT need to have any experience with Docker
65+
- We will help you install Eclipse, Visual Studio Code, Git client, Docker Desktop and Node JS (for npm)
66+
67+
## Who is this course for
68+
- You are a Java Spring Boot developer getting started with the Cloud
69+
- You want to containerize your Java applications with Docker
70+
- You are a Java Developer and You are curious about Docker
71+
- You want to learn to containerize a Java Spring Boot full stack application with Docker
72+
- You want to learn to play with Docker and Spring Boot Microservices - Service Registry, Distributed Tracing and Zuul API Gateway
73+
74+
## Step By Step Details
75+
76+
### Introduction to the Course
77+
- 00 Step 01 - Deploy Spring Boot Applications to Docker - Course Overview
78+
- 00 Step 02 - Deploy Spring Boot Applications to Docker - Getting Started
79+
80+
81+
82+
```sh
83+
for file in *; do mv "${file}" "${file//-/ }"; done
84+
for file in *; do mv "${file}" "${file// / - }"; done
85+
for file in *; do mv "${file}" "${file//01 Step/Step}"; done
86+
```
87+
88+
89+
### Commands Executed during the course
90+
91+
```
92+
System.out.println("Ranga")
93+
List<Integer> numbers = List.of(12, 9, 13, 4, 6, 2, 4, 12, 15);
94+
numbers.stream().reduce(0, (x,y)->x+y)
95+
numbers.stream().reduce(0, (x,y)->x)
96+
numbers.stream().reduce(0, (x,y)->y)
97+
numbers.stream().reduce(0, (x,y)-> x>y ? x:y)
98+
numbers.stream().reduce(Integer.MIN_VALUE, (x,y)-> x>y ? x:y)
99+
numbers.stream().reduce(Integer.MIN_VALUE, (x,y)-> x>y ? y:x)
100+
numbers.stream().reduce(Integer.MAX_VALUE, (x,y)-> x>y ? y:x)
101+
numbers
102+
numbers
103+
numbers.stream().reduce(0, (x,y) -> x*x + y*y)
104+
numbers.stream().map(x -> x*x).reduce(0, Integer::sum)
105+
numbers.stream().map(x -> x*x*x).reduce(0, Integer::sum)
106+
numbers.stream().filter(x -> x%2==1).reduce(0, Integer::sum)
107+
numbers.stream().filter(x -> x%2==0).reduce(0, Integer::sum)
108+
numbers.stream().distinct().forEach(System.out::println)
109+
numbers
110+
numbers.stream().sorted().forEach(System.out::println)
111+
numbers.stream().distinct().sorted().forEach(System.out::println)
112+
List<String> courses = List.of("Spring", "Spring Boot", "API" , "Microservices","AWS", "PCF","Azure", "Docker", "Kubernetes");
113+
courses
114+
courses.stream().sorted().forEach(System.out::println)
115+
courses
116+
courses.stream().sorted().forEach(System.out::println)
117+
courses.stream().sorted(Comparator.naturalOrder()).forEach(System.out::println)
118+
courses.stream().sorted(Comparator.reverseOrder()).forEach(System.out::println)
119+
courses.stream().sorted(Comparator.comparing(str -> str.length())).forEach(System.out::println)
120+
numbers
121+
courses
122+
courses.stream().map(x -> x.length()).collect(Collectors.toList())
123+
numbers.stream().map(x -> x*x).collect(Collectors.toList())
124+
Supplier<String> supplier = () -> {return "Ranga";};
125+
Consumer<String> consumer = (str) -> { System.out.println(str);System.out.println(str);};
126+
127+
128+
numbers.stream()
129+
List<Integer> numbers = List.of(12, 9, 13, 4, 6, 2, 4, 12, 15);
130+
numbers.stream()
131+
Stream.of(12, 9, 13, 4, 6, 2, 4, 12, 15).count()
132+
Stream.of(12, 9, 13, 4, 6, 2, 4, 12, 15).reduce(0, Integer::sum)
133+
Stream.of(12, 9, 13, 4, 6, 2, 4, 12, 15)
134+
int[] numberArray = {12, 9, 13, 4, 6, 2, 4, 12, 15};
135+
Arrays.stream(numberArray)
136+
Arrays.stream(numberArray).sum()
137+
Arrays.stream(numberArray).average()
138+
Arrays.stream(numberArray).min()
139+
Arrays.stream(numberArray).max()
140+
IntStream.range(1,10)
141+
IntStream.range(1,10).sum()
142+
IntStream.rangeClosed(1,10).sum()
143+
IntStream.iterate(1, e -> e + 2).limit(10).sum()
144+
IntStream.iterate(1, e -> e + 2).limit(10).peek(System.out::println).sum()
145+
IntStream.iterate(2, e -> e + 2).limit(10).peek(System.out::println).sum()
146+
IntStream.iterate(2, e -> e * 2).limit(10).peek(System.out::println).sum()
147+
IntStream.iterate(2, e -> e * 2).limit(10).boxed().collect(Collectors.toList())
148+
Integer.MAX_VALUE
149+
Long.MAX_VALUE
150+
IntStream.rangeClosed(1,50).reduce(1, (x,y)->x*y)
151+
LongStream.rangeClosed(1,50).reduce(1, (x,y)->x*y)
152+
LongStream.rangeClosed(1,50).reduce(1L, (x,y)->x*y)
153+
LongStream.rangeClosed(1,10).reduce(1, (x,y)->x*y)
154+
LongStream.rangeClosed(1,20).reduce(1, (x,y)->x*y)
155+
LongStream.rangeClosed(1,40).reduce(1, (x,y)->x*y)
156+
LongStream.rangeClosed(1,50).mapToObj(BigInteger::valueOf).reduce(BigInteger.ONE, BigInteger::multiply)
157+
158+
courses.stream().collect(Collectors.joining(" "))
159+
courses.stream().collect(Collectors.joining(","))
160+
"Spring".split("")
161+
courses.stream().map(course -> course.split("")).collect(Collectors.toList())
162+
courses.stream().map(course -> course.split(""))
163+
courses.stream().map(course -> course.split("")).flatMap(Arrays::stream).collect(Collectors.toList())
164+
courses.stream().map(course -> course.split("")).flatMap(Arrays::stream).distinct().collect(Collectors.toList())
165+
List<String> courses = List.of("Spring", "Spring Boot", "API" , "Microservices","AWS", "PCF","Azure", "Docker", "Kubernetes");
166+
List<String> courses2 = List.of("Spring", "Spring Boot", "API" , "Microservices","AWS", "PCF","Azure", "Docker", "Kubernetes");
167+
courses.stream().flatMap(course -> courses2.stream().map(course2 -> List.of(course,course2))).collect(Collectors.toList())
168+
courses.stream().flatMap(course -> courses2.stream().map(course2 -> List.of(course,course2))).filter(list -> list.get(0).equals(list.get(1))).collect(Collectors.toList())
169+
courses.stream().flatMap(course -> courses2.stream().map(course2 -> List.of(course,course2))).filter(list -> !list.get(0).equals(list.get(1))).collect(Collectors.toList())
170+
courses.stream().flatMap(course -> courses2.stream().filter(course2 -> course2.length()==course.length()).map(course2 -> List.of(course,course2))).filter(list -> !list.get(0).equals(list.get(1))).collect(Collectors.toList())
171+
courses.stream().filter(courses -> courses.length()>11).map(String::toUpperCase).findFirst()
172+
courses.stream().peek(System.out::println).filter(courses -> courses.length()>11).map(String::toUpperCase).peek(System.out::println).findFirst()
173+
courses.stream().peek(System.out::println).filter(courses -> courses.length()>11).map(String::toUpperCase).peek(System.out::println)
174+
$4.findFirst()
175+
List<String> courses = List.of("Spring", "Spring Boot", "API" , "Microservices","AWS", "PCF","Azure", "Docker", "Kubernetes");
176+
courses.replaceAll( str -> str.toUpperCase())
177+
List<String> modifyableCourses = new ArrayList(courses);
178+
modifyableCourses.replaceAll(str -> str.toUpperCase())
179+
modifyableCourses
180+
modifyableCourses.removeIf(course -> course.length()<6)
181+
modifyableCourses
182+
183+
```
184+
185+
## Next Steps
186+
187+
## Todo
188+
- Course Promotion Emails/Posts
189+
- 2 Emails on Udemy
190+
- 2 Emails to Email List
191+
- Create YouTube Course Preview Video
192+
- Add YouTube Course Preview Video as End Video for all videos
193+
- Make it the YouTube Default Video
194+
- Release atleast 20 small videos - one a day on Youtube
195+
- Do atleast 3 Youtube live sessions
196+
- After a Month
197+
- UFB and Packt
198+
199+
200+
201+
### Later
202+
203+
- collect(ArrayList::new, ArrayList::add, ArrayList::addAll)
204+
- partitioningBy
205+
206+
Behavior Parameterization
207+
-> Tracing Performance of methods -> Pass function to track as a parameter
208+
-> Externalize Sort Behavior as a parameter
209+
210+
Function Composition
211+
- Function<String, Integer> lengthBis = unNullify.andThen(length);
212+
- Function<String, Integer> lengthBis = length.compose(unNullify);
213+
Consumer.andThen
214+
- Predicate<String> startsWithJAndLengthIs7 = startsWithJ.and(lengthIs7);
215+
- Predicate<String> lengthIs9orError = lengthIs9.or(equalsError);
216+
217+
Design Patterns
218+
- Decorator Pattern
219+
- Template Method - Execute Around Pattern
220+
- Strategy Pattern - Even/Odd/Prime
221+
222+
Play based on Position:
223+
- IntStream.range(0, input.size()).filter(pos -> input.get(pos).length() > pos).mapToObj(pos -> input.get(pos)).collect(Collectors.toList());
224+
225+
Lambda Expressions in Unit Tests => assertThrows
226+
227+
Currying f(x,y) = (g(x))(y)
228+
- int function(BiFunction<Integer,Integer,Integer> func, Integer value1, Integer value2) { return func.apply(value1,value2); }
229+
- function((x,y) -> x + y, 2, 3)
230+
- BiFunction<Integer, Integer, Integer> curry(BiFunction<Integer,Integer,Integer> func) { return (x,y) -> func.apply(x,y); }
231+
- BiFunction<Integer, Integer, Integer> add = curry( (x,y) -> x+y)
232+
add.apply(1,2)
233+
234+
Map Operations
235+
- keys.forEach(key -> map.compute(key, (k, v) -> v == null ? k : v.toUpperCase()));
236+
- map.computeIfAbsent,Present,merge,putIfAbsent, computeIfPresent
237+

src/programming/FP01Exercises.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package programming;
2+
3+
import java.util.List;
4+
5+
public class FP01Exercises {
6+
7+
public static void main(String[] args) {
8+
List<Integer> numbers = List.of(12, 9, 13, 4, 6, 2, 4, 12, 15);
9+
printCubesOfOddNumbersInListFunctional(numbers);
10+
// printOddNumbersInListFunctional(numbers);
11+
12+
List<String> courses = List.of("Spring", "Spring Boot", "API" , "Microservices","AWS", "PCF","Azure", "Docker", "Kubernetes");
13+
14+
// courses.stream()
15+
// .forEach(System.out::println);
16+
17+
// courses.stream()
18+
// .filter(course -> course.contains("Spring"))
19+
// .forEach(System.out::println);
20+
21+
// courses.stream()
22+
// .filter(course -> course.length() >= 4)
23+
// .forEach(System.out::println);
24+
25+
courses.stream()
26+
.map(course -> course + " " + course.length())
27+
.forEach(System.out::println);
28+
}
29+
30+
private static void printOddNumbersInListFunctional(List<Integer> numbers) {
31+
numbers.stream() // Convert to Stream
32+
.filter(number -> number % 2 != 0) // Lamdba Expression
33+
.forEach(System.out::println);// Method Reference
34+
}
35+
36+
private static void printCubesOfOddNumbersInListFunctional(List<Integer> numbers) {
37+
numbers.stream() // Convert to Stream
38+
.filter(number -> number % 2 != 0) // Lamdba Expression
39+
.map (number -> number * number * number)
40+
.forEach(System.out::println);// Method Reference
41+
}
42+
43+
}

src/programming/FP01Functional.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package programming;
2+
3+
import java.util.List;
4+
5+
public class FP01Functional {
6+
7+
public static void main(String[] args) {
8+
List<Integer> numbers = List.of(12, 9, 13, 4, 6, 2, 4, 12, 15);
9+
// printAllNumbersInListFunctional(numbers);
10+
//printEvenNumbersInListFunctional(numbers);
11+
printSquaresOfEvenNumbersInListFunctional(numbers);
12+
}
13+
14+
// private static void print(int number) {
15+
// System.out.println(number);
16+
// }
17+
18+
// private static boolean isEven(int number) {
19+
// return number%2 == 0;
20+
// }
21+
22+
private static void printAllNumbersInListFunctional(List<Integer> numbers) {
23+
// What to do?
24+
numbers.stream().forEach(System.out::println);// Method Reference
25+
}
26+
27+
// number -> number%2 == 0
28+
private static void printEvenNumbersInListFunctional(List<Integer> numbers) {
29+
// What to do?
30+
31+
numbers.stream() // Convert to Stream
32+
.filter(number -> number % 2 == 0) // Lamdba Expression
33+
.forEach(System.out::println);// Method Reference
34+
35+
// .filter(FP01Functional::isEven)//Filter - Only Allow Even Numbers
36+
}
37+
38+
private static void printSquaresOfEvenNumbersInListFunctional(List<Integer> numbers) {
39+
numbers.stream() // Convert to Stream
40+
.filter(number -> number % 2 == 0) // Lamdba Expression
41+
//mapping - x -> x * x
42+
.map(number -> number * number)
43+
.forEach(System.out::println);// Method Reference
44+
45+
// .filter(FP01Functional::isEven)//Filter - Only Allow Even Numbers
46+
}
47+
48+
}

0 commit comments

Comments
 (0)