Java Intro

  • Java is platform independent

    • There is a virtual machine for every system

    • Code is written for the virtual machine not for the system

    • Java VM runs the code

      • VM = Virtual Machine

  • This gives flexibility, decreases the speed a little


JRK versus LDK

  • JRK: Java Runtime Environment

    • Necessary to run the java code

    • Contains libraries, etc.

    • has VM inside (java)

  • JDK: Java Development kit

    • Necessary to compile the java code

    • Contains the java compiler (javac)

    • It also contains JRE


Compiling vs. Interpreting

  • Compiling:

    • Prepare the code for the machine

    • Optimize it

    • C/C++ are compiled

  • Interpretating:

    • Run the code line by line

    • No optimization, or minimal

    • Python, Javascript, and PHP are interpreted


Compiliation Example

int i = 90;
int b = 10;
int result = 0;
i = i - b;
result++;
while (i >= b) {
    i = i - b;
    result ++;
}

becomes

int i = 90;
int b = 10;
int result = 0;
while (i >= b) {
    i = i - b;
    result ++;
}

becomes

int i = 90;
int b = 10;
int result = i / b;
int remainder = i % b;

→ always use meaningful names while naming variables


Does Java compile or interpret?