L2: Compiling and interpreting
Compiling:
Components of a computer system:
1) Compiler, assembler, text editor, database system
2) Operating system
3) Computer hardware
A compiler and an operating system read each other
Notes that are not in the slides about compiling:
1) We write our program in C++
2) #include is a compiler directive, I am telling the compiler to do something before compiling
3) Compile the application, (assuming there are no syntax errors) (Object Code, ones and zeros)
We still need the binary codes that are not from the program which leads to
4) Linking (adds the ones and zeros that are needed from outside the code)
5) Loader (loads the programs and libraries)
Two types of compiling:
AOT (Ahead of time):
ex: C++, C
There are no extra steps to do after compiling. This means that there can not be any changes to the
compilation later which might lead to difficulties.
JIT (just in time):
ex: Java
There are two steps of compiling. Compiling and interpreting.
1] Source code to byte code (AOT but half compiling)
2] interpreting byte code and executing. This is done by JVM, it converts byte code to machine code
[JIT]
JVM converts the code into a language that your machine specifically can understand
Let’s say we have Windows 10, MacOS, Linux, the program will run depending on where we are
compiling.
If we have an AOT, we want to make sure ahead of time that the compilation will match the OS
we are working on since that might vary depending on the hardware the OS exists on.
If we have JIT, the second step will make the code executable on every machine which is written
by JVM. So, all machine that have JVM virtual machine can run JVM interpreted code.