Skip to content

Commit b6d7483

Browse files
All The Stuff About Maven + Fibonacci Implementation
2 parents a4af42c + 2ea09fd commit b6d7483

File tree

5 files changed

+399
-6
lines changed

5 files changed

+399
-6
lines changed
File renamed without changes.
File renamed without changes.

Dynamic_Pro/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,47 @@
11
### Dynamic Programming
2+
3+
4+
5+
#### Fibonacci Algorithm
6+
7+
- A Tree like data structure
8+
- Any computation I made within the tree that I plug into the formula ...
9+
- I shouldn't have to compute again thanks to memoization it stores the value
10+
- in an object and spits it out whenever there is a call to it
11+
- I store the answer within the memo and caches that result
12+
- My key is the nth number in the fibonacci sequence
13+
- My value is the value i.e. output
14+
- When making recursive calls, thanks to memoization, it outputs a stored value
15+
- and doesn't have to travel through any further subtrees
16+
- So memoizing my fib function ends up reducing the number of recursive calls I make
17+
18+
##### Runtime Complexity
19+
20+
- Memoizing my algo I see a linear functional call pattern
21+
- i.e. I have n node and that's why the runtime complexity is O(n)
22+
- where n is the top level call
23+
24+
##### Space Time Complexity
25+
26+
- O(n)
27+
28+
29+
#### Grid Traveler
30+
31+
- You want to travel
32+
- You start at the top left corner and your goal is to end in the bottom right corner
33+
- You can only go down or to the right
34+
- You CANNOT move up or left or diagonally
35+
- Find the # of different ways you can travel
36+
- gridTravelTo(2,3) means how many different ways you can travel
37+
- ...from the top left to bottom right in a 2x3(2 rows by 3 columns)
38+
- 3 dif ways:
39+
- right, right, down
40+
- right,down, right,
41+
- down, right, right
42+
- gridTravelTo(1) means do nothing because you are already there
43+
- gridTravelTo(0,1) means 0 rows and 1 column i.e. the grid is empty
44+
- gridTravelTo(1,0) means 1 row and 0 columns i.e. the grid is empty
45+
- gridTravelTo(8,0) means 8 rows and 0 columns i.e. the grid is empty
46+
- gridTravelTo(0,0) means 0 rows and 0 columns i.e. the grid is empty
47+
- base case: if one of your dimensions is empty then there is no grid

Maven/README.md

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
## Maven
2+
3+
- PM tool for JVM Languages
4+
5+
- Used To Perform Major Tasks:
6+
- Build Your Source Code
7+
8+
- Testing Your Code
9+
10+
- Packaging Your Code(JAR, WAR, EAR)
11+
12+
- Generate Java docs
13+
14+
- Dependency Management
15+
16+
- Handling, Versioning Your Artifacts
17+
18+
19+
### How To Install:
20+
21+
- Head over to: https://maven.apache.org/download.cgi
22+
- Download the Binary Zip Archive
23+
- Extract It
24+
25+
### 2- Create an environment variable in your system name it M2_HOME
26+
27+
- This is where Other SW and libraries look for the Maven Installation
28+
- Give it a path in the bin folder
29+
30+
### Checking if the installation is successful
31+
32+
```bash
33+
mvn --version
34+
```
35+
36+
### File Structure
37+
38+
```
39+
├── /my-project-demo
40+
├── /.idea
41+
├── /src
42+
├── /main
43+
├── /java
44+
└── /resources
45+
├── /test
46+
└── /java
47+
├── /target
48+
└── pom.xml
49+
├── /External Libraries
50+
└── /Scratches and Consoles
51+
```
52+
53+
- All the static files go in our resources folder
54+
- e.g. Property Files, or any file we need to read from(xml, csv,html, css, js)
55+
- test file I store all my unit tests and integration tests
56+
- pom.xml holds all the metadata of my Application i.e. project dependencies
57+
- target folder holds all the java compiled class files
58+
59+
60+
### Creating A Project
61+
62+
- Give it an artifact id(this is usually the name of your project) e.g. my-project-demo
63+
- Give it group Id(this is usually the name of your company id in reverse order i.e. com.herokuapp.omarbelkady)
64+
- Give it a version number e.g. 1.0-SNAPSHOT
65+
66+
67+
### 3rd Party JAR files i.e. Dependencies
68+
69+
- External Libraries are called "dependencies"
70+
- Maven provides me with functionality on how to manage my dependencies
71+
- ...thanks to the pom.xml file
72+
73+
74+
### Life Without Maven
75+
76+
- I have to manually download the JAR files from the internet
77+
- then I add them one by one
78+
79+
80+
### Dependency Section Thanks To Maven
81+
82+
- Maven provides me with a dependency section where I can specify the info of the JAR I require in my project
83+
- artifactid
84+
- groupid
85+
- version
86+
- Maven will then automatically download these dependency specified, from the internet and load them into my project
87+
- Load each dependency in a "dependency" tag
88+
- And all your depenency tags should be in between 1 dependencies tag
89+
90+
< dependencies >
91+
< dependencyA >
92+
93+
< /dependencyA >
94+
95+
< dependencyB >
96+
97+
< /dependencyB >
98+
< dependencies >
99+
100+
- To add a dependency go to https://www.mvnrepository.com/
101+
102+
103+
- Click on the Maven Icon to force IntelliJ to download the dependencies you have specified
104+
105+
106+
### Transitive Dependencies
107+
108+
- Dependencies of my dependencies
109+
110+
111+
```
112+
├── /my-project-demo
113+
├── /.idea
114+
├── /src
115+
├── /main
116+
├── /java
117+
└── /resources
118+
├── /test
119+
└── /java
120+
├── /target
121+
└── pom.xml
122+
├── /External Libraries
123+
└── /Scratches_and_Consoles
124+
```
125+
126+
- All the static files go in our resources folder
127+
- e.g. Property Files, or any file we need to read from(xml, csv,html, css, js)
128+
- test file I store all my unit tests and integration tests
129+
- pom.xml holds all the metadata of my Application i.e. project dependencies
130+
- target folder holds all the java compiled class files
131+
132+
### Maven Dependency
133+
- Can be categorized into two categories:
134+
- Snapshot Dependency
135+
- This dependency was created when the software was in active development
136+
- Unstable
137+
- Release Dependency:
138+
- This dependency was created after the software was developed and is ready to be released i.e. ready to be deployed for production
139+
- Stable
140+
141+
- In all, when I am developing the software I use the snapshot versions for the dependencies. When the software is released, I use the release versions
142+
143+
---
144+
### Dependency Scopes
145+
146+
- enables me to control the visibility of a Maven depenendency
147+
- 4 types:
148+
1. **Compile**: made available at compile time within classpath [default scope]
149+
2. **Provided**: dependency provided at runtime by JDK or webserver, e.g. Servlet API dependency. The web server which is running my project provides me with the java servlet-api during runtime. This means that the dependency will be available in the class path of the project but will not be packaged in the JAR file nor the WAR file
150+
3. **Runtime**: dependency provided ONLY at runtime and NOT at compile time e.g. MySQL JDBC connector dependency. I mark the dependency as runtime to make sure I do not use the MySQL JDBC classes in my code instead of standard jdbc api
151+
4. **Tests**: dependency only available at the time of writing and running my unit tests e.g. junit, spring-boot-starter-test
152+
5. **System**: the path to the JAR should be specified manually using the < systemPath > tag. The only restriction is that I must specify the exact path of where to locate this dependency within my system.
153+
154+
### Repositories
155+
- a special directory called a **repository** is the location where Maven stores my dependencies
156+
- Local Repository[directory/folder in your machine]
157+
- Remote Repository[Maven Website] where I can download the Maven dependencies
158+
- If a dependency I specified in my pom is not in my local repository it goes ahead and connects to the remote repository and downloads the remote repository and stores the dependency within my local repository
159+
160+
##### How To Define A Repository within my POM always after my closing dependency tag
161+
```xml
162+
<repositories>
163+
<repository>
164+
<id>my-internal-website</id>
165+
<url>https://myserver/repo</url>
166+
</repository>
167+
</repositories>
168+
```
169+
170+
171+
### Build Lifecycle Within Maven
172+
173+
- How Does Maven Build Our Projects?
174+
1. default
175+
2. clean
176+
3. site
177+
178+
#### Default Lifecycle Build Step Phases
179+
1. validate
180+
- Makes sure pom.xml is validated or not validated
181+
2. compile
182+
- Compiles my source code
183+
3. test
184+
- Runs the unit tests in my project
185+
4. package
186+
- Packages the source code into an artifact
187+
5. integration-test
188+
- Executes the integration tests
189+
6. verify
190+
- Verifies the results of the integrations tests
191+
7. install
192+
- Installs the newly created package files(JAR or any other artifact) within my local repository
193+
- Maven
194+
8. deploy
195+
- Deploy the newly created package to the remote repository
196+
- If the newly created package is configured in the pom.xml file it will deploy the new package into the remote repository
197+
198+
199+
### Command
200+
```java
201+
mvn clean install
202+
```
203+
204+
- This command compiles the source code
205+
- Runs the unit tests
206+
- Creates the JAR file
207+
- Install the JAR file into your local repository
208+
209+
### Site Step
210+
211+
- generate Java documentation that is present in my project
212+
213+
214+
### Plugins and Goals
215+
216+
- To be able to execute the different lifecyle phases, Maven provides me with different plugins in order for me to perform each task in the lifecycle
217+
- Every plugin has a relationship to a goal which is linked to the lifecycle phase(e.g. compile)
218+
- To declare a plugin simple place in between a **plugin** tag that is within the **plugins** tag
219+
- Any plugin I want to define must be within the build tag
220+
- The build tag will usually be right below the dependencies section
221+
222+
```xml
223+
<build>
224+
<plugins>
225+
<plugin>
226+
<groupId>org.apache.maven.plugins</groupId>
227+
<artifactId>maven-compiler-plugin</artifactId>
228+
<version>3.8.1</version>
229+
</plugin>
230+
</plugins>
231+
</build>
232+
```
233+
234+
- The plugin above is in charge of compiling any test files or source files I have within my project. This is familiar to running
235+
```java
236+
javac nameofclass.java
237+
```
238+
239+
240+
#### To trigger the compile lifecycle phase
241+
```java
242+
mvn compiler:compile
243+
```
244+
245+
### Maven tab⇒ Plugin section ⇒ Hit Expand ⇒ Click on Compile Goal
246+
247+
- Compilation fails
248+
- Java compiler of Maven within IntelliJ is configured to Java version 1.X
249+
- To fix:
250+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0. Go to your pom.xml
251+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1. Head to build section
252+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2. Plugins ⇒ plugin
253+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3. Configuration Tag
254+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4. Change the source & target properties to the java version installed on your machine
255+
256+
### Maven Install Plugin
257+
258+
- This plugin is used to run the install lifecycle phase within the maven build lifecycle
259+
1. Compiles My Source Code
260+
2. Runs Our Unit Tests
261+
3. Package The Cource Code into an Artifact
262+
4. Installs The Artifact Within My Local Repository
263+
264+
265+
### Maven Deploy Plugin
266+
267+
- Self-explanatory plugin
268+
- runs all the phases which are part of the install phase
269+
- deploys the created artifact to the remote repository
270+
0. To deploy the artifact to the remote repo you have to specify the remote repo details within your pom
271+
1. Create a tag right above your dependencies tag and give it a name of **distributionManagement**
272+
2. Within the distributionManagement tag create a tag named **repository** and place the information of your repository there
273+
3. To uniquely identify a repository I specify the **id**, **name** and **url**
274+
4. Run the command below to deploy your plugin
275+
276+
```java
277+
mvn clean deploy
278+
```
279+
280+
### Maven Profiles
281+
282+
- Profiles can be used within maven to create customized build configurations within my project
283+
- I can customize the behavior of a build based upon specific conditions
284+
- e.g. I can skip the test execution due to the fact that my build process may take a long time
285+
- I create a profile that will skip the test execution phase
286+
287+
##### How To Create
288+
289+
- Right below your build tag create a **profiles** tag
290+
291+
- Within your profiles tag create a **profile** tag I give it an:
292+
- *id*
293+
- *properties*
294+
295+
- After creating a profile for the above example Maven will make sure to skip the test execution
296+
297+
- I head over to the terminal and run the following command:
298+
- -P flag indicates the id of the profile
299+
```java
300+
mvn -Pskip-tests clean install
301+
```

0 commit comments

Comments
 (0)