diff --git a/content/courses/prog-intro/lectures/assets/edge-case-for-link-counting.svg b/content/courses/prog-intro/lectures/assets/edge-case-for-link-counting.svg new file mode 100644 index 0000000..4c21e36 --- /dev/null +++ b/content/courses/prog-intro/lectures/assets/edge-case-for-link-counting.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/content/courses/prog-intro/lectures/assets/int-in-memory.svg b/content/courses/prog-intro/lectures/assets/int-in-memory.svg new file mode 100644 index 0000000..7840001 --- /dev/null +++ b/content/courses/prog-intro/lectures/assets/int-in-memory.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/content/courses/prog-intro/lectures/assets/string-in-memory.svg b/content/courses/prog-intro/lectures/assets/string-in-memory.svg new file mode 100644 index 0000000..35700ee --- /dev/null +++ b/content/courses/prog-intro/lectures/assets/string-in-memory.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/content/courses/prog-intro/lectures/intro.md b/content/courses/prog-intro/lectures/intro.md index 80580d1..4d021ac 100644 --- a/content/courses/prog-intro/lectures/intro.md +++ b/content/courses/prog-intro/lectures/intro.md @@ -88,4 +88,58 @@ Java comes in two parts: **JDK - Java Development Kit** and **JVM - Java Virtual There is also a **JRE - Java Runtime Environment**. For example if we want to run our code somewhere on the server we don't need to compile it there because we have our byte code and we just need JRE to run it. +Some of the most popular JVMs right now are: + +- OpenJDK +- Eclipse +- Azul Systems +- Excelsior JET + +The disadvantage of such system is in the connection between JVM and a native processing unit. In case of C++ compiler that we reviewed earlier the source code is compiled directly into machine-code but in case with Java it is compiled into byte-code. And so the problem is to develop such a JVM that would quickly turn our byte-code into machine-code. Anyway it takes extra time. That's why it mostly will be slower than direct compilation into machine-code. So ultimately while we have the advantage of compiling out code only once, we have the disadvantage of turning byte-code into machine-code slower. + +None the less, there is a way to speed up this process which is called JIT - Just In Time compilation. How does it work? While our program is running some of the instructions or functions turns directly into processor commands. + +# What is garbage collection? + +For example we have `int` which is represented with 4 bytes of data which is directly stored in memory. + + +*Img. X -- `int` in memory* + +But what if we have a `String`. How many memory cells does this string take? We don't know. We will say that our `String` that has length of 5 symbols is stored at `0x12347865`. We defined an address where this string is located in memory. And somewhere in the memory of our programm will be a large buffer where the 5 cells will be stored. + + +*Img. X -- `String` in memory* + +But what do we do with that buffer? We won't need it forever and so sometimes we need to clear that buffer. In case with C/C++ whoever created the memory for that string is in charge of clearing it. There are also languages with garbage collection such as Java and Python. The purpose of the **Garbage Collector** is to automatically find variables that we no longer need and clear their memory. + +Suppose we have some code like this. + +```java +if (someCondition) { + x = [1, 3, 7] // first link + // some code here + y = x // second link + // some code here +} // no links +``` + +After the `if`-statement we no longer need `x` or `y`. Every variable in this case `x` and `y` is the link to our array (`[1, 3, 7]`). After we left the `if`-statement the amount of links to the array is zero, so we can safely delete the array. This approach is implemented in Python. The problem is that if we have to objects linked to one another and there are no external links, they will not be deleted by garbage collector since there link counter is 1. + + +*Img. X -- Edge case for link counting* + +The advanced way of implementing the garbage collection is *traversing the graph of links* which is implemented in Java, C# and Go. + +# What other advantages does Java have? + +- It's easy (in terms of syntax) +- It's secure and stable +- It supports Unicode +- It supports multithreading +- It has backwards compatibility + +# How should Java code look like? + +You can go and learn about it [here](https://google.github.io/styleguide/javaguide.html). diff --git a/public/courses/prog-intro/lectures/assets/edge-case-for-link-counting.svg b/public/courses/prog-intro/lectures/assets/edge-case-for-link-counting.svg new file mode 100644 index 0000000..4c21e36 --- /dev/null +++ b/public/courses/prog-intro/lectures/assets/edge-case-for-link-counting.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/public/courses/prog-intro/lectures/assets/int-in-memory.svg b/public/courses/prog-intro/lectures/assets/int-in-memory.svg new file mode 100644 index 0000000..7840001 --- /dev/null +++ b/public/courses/prog-intro/lectures/assets/int-in-memory.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/public/courses/prog-intro/lectures/assets/string-in-memory.svg b/public/courses/prog-intro/lectures/assets/string-in-memory.svg new file mode 100644 index 0000000..35700ee --- /dev/null +++ b/public/courses/prog-intro/lectures/assets/string-in-memory.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/public/courses/prog-intro/lectures/intro/index.html b/public/courses/prog-intro/lectures/intro/index.html index 730fb2e..3ee8d7a 100644 --- a/public/courses/prog-intro/lectures/intro/index.html +++ b/public/courses/prog-intro/lectures/intro/index.html @@ -53,7 +53,7 @@ What does Java consist of?Java consists of multiple main components. The first o Img. 1 - TIOBE Programming Community Index Also, Java has a lot of advantages for beginners such as: It’s fairly easy It has a broad spectre of usage Server Desktop Mobile devices Smart-cards What does Java consist of?Java consists of multiple main components. The first one being the Java compiler. The process of converting human-readable text to machine code is called compilation."> - + -