Java Execution Process + Spring dependencies(Implementation , runtimeOnly , compileOnly , annotationProcessor ) : Where Are These Dependencies Used?

#Foreword

I didn't intend to study Java Execution Process Flows initially. However, when i needed to add dependencies in Spring Boot, I found myself pondering over terms like implementation, runtimeOnly, compileOnly, annotationProcessor, and related concepts.

To be honest, although I've never cared about these specific concepts before, I realized that to use dependencies properly, I needed to understand them. Thanks to this curiosity, I started to recognize Java Execution Process Flows. Some people say that if you encounter something you don't understand in Spring, you should consider Java first. Furthermore, when I encounter something difficult to understand, I've found that creating documentation is a good part of the output. I am glad I'm endeavoring to create another document, and I hope to gain a solid understanding of new Java concepts.

<Java Execution Process>

  1. javaExeFlow.java -> Written Java Code : Human-Readable Form

    : Java code is written by developers

    ㅡㅡㅡㅡㅡㅡㅡCompile Timeㅡㅡㅡㅡㅡㅡㅡ

  2. javaExeFlow.javac -> Compilation : Compiler generates Bytecode

    : Java code is compiled by the Java Compiler (javac) into bytecode, which is platform-independent through an OS independent compiler

  3. javaExeFlow.class -> Loading Bytecode into Memory

    : The compiled bytecode is loaded into memory

  4. JVM Bytecode Interpretation -> Execute program's logic

    : The Java Virtual Machine (JVM) interprets the bytecode instructions to execute program's Logic

  5. Domain-Specific Language by JVM -> make it compatible with DSL

    : The JVM translates the bytecode into a domain-specific language, making it compatible with the JVM's execution environment.

    ㅡㅡㅡㅡㅡㅡㅡRun Timeㅡㅡㅡㅡㅡㅡㅡ

  6. JVM Runtime Operation -> Executes Program's Logic during its runtime

    : During runtime (During the execution of a Java Programs), the JVM performs various tasks including memory allocation, garbage collection, other necessary operations (other tasks).

  7. JVM Program Execution Termination -> Exit Program

    : The program terminates and exits gracefully

cf) Why Java is platform-Indepent Langauge?

  1. Java - Platform Indepent Language

Java is a platform-independent programming language, which is not one-step compilation, instead, it involves two - step execution.

First -> is compiled through OS independent compiler

Second -> By JVM(Java Virtual Machine) -> It's customized to be compatible with specific OS (Custom-Built)

  1. Bytecode - a machine independent encoding by javac

Java Compiler encodes the java source code into a machine-independent encoding

  1. JVM - Executing Java Program , Managing Runtime Environment

Java Virtual Machine is responsible for executing Java Programs and managing their runtime environment. In other words, Java Virtual machine is responsible for overseeing all aspects of program execution including runtime operation to ensure the proper functioning of the Java application.

#build.grade - Spring dependencies, Where Are These Dependencies Used?

:: The scope of dependencies in the spring framework

<Compilation Time>

  1. Implementation -> Used both during compilation time and runtime application

  2. compileOnly -> Only used during compilation time, not during runtime application

  3. annotationProcessor -> Used only during compilation time. It generates additional code from requested annotations, serving the role of an annotation processor. (annotations like @RequiredArgsConstructor can help reduce boilerplate code like constructors.)

  4. annotationProcessor: Used only during compilation time. It generates additional code from requested annotations, serving the role of an annotation processor. For example, annotations like @RequiredArgsConstructor can help reduce boilerplate code like constructors.

  1. testImplementation -> Necessary for compiling and running test code, but not included in runtime environment of the main application.

<Run Time>

  1. Implementation -> Used both during compilation time and runtime application

  2. runtimeOnly -> Only used during runtime application, not during compilation time.