# Understanding Java Development Kit

* Java is a compiled and interpreted language.

1. JDK is a combination of development tools and JRE
2. `/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin` in linux, consist of all the java development tools.
3. JRE stands for Java runtime environment, which consits of API _(run time libraries)_.
4. `/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/rt.jar` in linux, consist of all the java package folders and files stored in jar packaging format.
5.  To view them using jar tool use the command,

    ```sh
    jar tvf rt.jar
    ```
6. How java achieves platform independence i.e philosophy of WORA?
   * When we compile the java source file using java compiler, it generates an intermediate byte code(`.class` file) which is platform independent. This `.class` files cannot run on any platform(OS + hardware) directly.
   * As this .class file cannot be run on any real machine, we need a virtual machine to convert this platform independent code to platform specific code. This is where we need a translator and `JVM` acts as a translator. Hence, `JVM` is platform specific, and acts as a translator.
7. What does JVM do?
   * JVM load and execute all the required classes.
   * Components of JVM
     1. `class loader`, which loads all the classes in JVM memory(in to something called method area).
        * Phases involved in class loader
          * Loading
          * Linking
            * Verify : Checks correctness of `.class` file
            * Prepare : Allocates memory for static fields of class/interface and initialize them with default value.
            * Resolve : Symbolic references with direct references.
          * Initializing
     2. Runtime memory area
        * Method area
        * Heap
        * Stack per thread
        * Program counters per thread
        * Native method stack
     3. Execution Engine
        * `Interpreter`, which takes intermediate byte code as input and outputs platform specific native code _(This code is directly runnable on hardware)_.
        * `JIT(Just in time compiler)`, basically use native code cache to make code interpretation faster by storing repeatedly occurring code in to native cache after being translated. JIT consists of,
          * Intermdiate code generator : Generates intermediate code.
          * Target code generator : Convert intermediate code to native machine code.
          * Code optimizer : Optimize intermediate code generated
          * Hotspot profiler : Finds the hot spots in the code.
        * Garbage collector
     4. Native method interface _(JNI)_
     5. Native method library

* More detailed article about it [here](https://www.freecodecamp.org/news/jvm-tutorial-java-virtual-machine-architecture-explained-for-beginners/).
* More about garbage collector is [here](https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/toc.html).
* JDK structure for java 8 is [here](https://docs.oracle.com/javase/8/docs/technotes/tools/windows/jdkfiles.html)
