content(resources): clean up markdown files, headings & codeblocks

This commit is contained in:
Jean-Philippe Sirois
2020-05-13 07:10:53 -04:00
parent 1d42773186
commit 6356927a35
10 changed files with 110 additions and 117 deletions
+3 -3
View File
@@ -1,11 +1,11 @@
---
authors:
- "AstronautEVA#0331"
title: "What is a class?"
title: "Classes"
created_at: 2019/10/20
---
# What is a class?
## What is a class?
Oftentimes in programs, it is necessary to represent objects from the real world as computer data.
For example, if someone is writing a program that simulates a zoo, they will need to create some animals.
@@ -56,7 +56,7 @@ public class Animal {
}
```
### Class vs Object
## Class vs Object
Remember this is only the description of what an animal is, not a specific animal. A specific animal such as Max is one instance of a class and is called an object. It has values assigned to its attributes like the name is Max and the age is 5. You can call methods on the object such as move or sleep. And there can be an infinite number of objects constructed from a class. To create objects from your class, you need something called a constructor.
+4 -4
View File
@@ -1,13 +1,13 @@
---
authors:
- "AstronautEVA#0331"
title: "What is Inheritance?"
title: "Inheritance"
created_at: 2019/10/24
recommended_reading:
- java/class
---
# What is Inheritance?
## What is Inheritance?
Inheritance is the idea that when two classes have similar implementations, rather than duplicating code for each class one can obtain it from the other. Much like a human child will inherit traits from their parents, a child class will inherit data from
its parent class.
@@ -123,7 +123,7 @@ public class Animal {
It can be used in our subclass.
```
```java
Animal myAnimal = new Animal();
myAnimal.sleep(); // returns "The animal sleeps."
@@ -145,7 +145,7 @@ public class Bird extends Animal {
It cannot be used in our superclass.
```
```java
Animal myAnimal = new Animal();
myAnimal.chirp(); // error, the method does not exist
+2 -4
View File
@@ -8,8 +8,6 @@ external_resources:
href: https://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/
---
## An introduction to Streams
Basically everyone, who spent a few hours coding some Java came across a situation like this:
```java
@@ -30,7 +28,7 @@ Arrays.stream(intArray).forEach(n -> System.out.println(n));
You just made one line out of three. But how does this work? `int[] intArray = {1,2,3,4,5};` does just declare and initialize a new array of integers. This stays the same as before, because you can use the `Arrays.stream()` method for every Array, [as it works with generic Arrays](https://www.mkyong.com/java8/java-how-to-convert-array-to-stream/). This method creates a [Stream Object](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html), that has several methods to perform operations on an array.
### Sorting
## Sorting
Now maybe you have a list instead of an array and you also want the list to get sorted before you print it. Without Streams you would first have to sort the list and then iterate through it. Way too many lines! Using Streams you can simply do:
@@ -46,7 +44,7 @@ intList.stream().sorted().forEach(n -> System.out.print(n + ", "));
At the end, you have again only one line, for sorting and printing every element in a list. Due to the fact that Streams mostly use Method Chaining, you could perform a bunch of operations.
### Filtering
## Filtering
Now you are able to print out every element of an array, a list, a stack, etc. sorted as well as unsorted. The last essential operation is, how to filter your array/list. One often has to only get specific elements of an array. Using Streams you could do it like this: