Compilation and Execution

Introduction

  • During Compilation(Compile time), the compiler convert source code (.java) into bytecode (.class)

  • Compile Time Error is mainly related to syntax error of source code

  • During Execution (Run time), the class file will read ,the related class will be loaded and the relevant information (e.g: static variable, method ) will be stored into memory of JVM

  • Run time Error is mainly related to out of memory, divided by 0 ,dereferencing a null pointer

JVM Memory
  • Finally , the class file will be read line by line , data in memory area , convert into native machine code and be executed by execution engine

  1. JDK(Java Development Kit) : JDK is intended for software developers and includes development tools such as the Java compiler, Javadoc, Jar, and a debugger.

  2. JRE(Java Runtime Environment) : JRE contains the parts of the Java libraries required to run Java programs and is intended for end users. JRE can be view as a subset of JDK.

  3. JVM: JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed. JVMs are available for many hardware and software platforms.

Heap and Stack

Heap

  • Used to store the address of the object such as String, ...

  • If heaps is fulled, Out of memory error will be thrown

Stack

  • When the method is executed, a new stack will be created and the local primitive variable and the reference of the object which can be found in heaps will be stored

  • After execution of the method, the corresponding stack frame will be flushed

  • Last in First Out

Garbage Collection

  • In order to prevent out of memory, as there are many unused objects, the heap memory will be cleared automatically in the background

Last updated

Was this helpful?