In order to write and execute a software program you need the following
1) Editor – To type your program into , a notepad could be used for this
2) Compiler – To convert your high language program into native machine code
3) Linker – To combine different program files reference in your main program together.
4) Loader – To load the files from your secondary storage device like Hard Disk , Flash Drive , CD into RAM for execution. The loading is automatically done when your execute your code.
5) Execution – Actual execution of the code which is handled by your OS & processor.
With this background, refer the following video & learn the working and architecture of the Java Virtual Machine.
Please be patient . Video will load in some time. If you still face issue viewing video click here
After Thoughts --
why is Java both interpreted and complied language ?
Programming languages are classifies as
Higher Level Language Ex. C++ , Java
Middle Level Languages Ex. C
Low Level Language Ex Assembly
& finally the lowest level as the Machine Language.
A compiler is a program which converts a program from one level of language to another. Example conversion of C++ program into machine code.
The java compiler is a convert’s high level java code into bytecode (which is also a type of machine code).
A interpreter is a program which converts a program at one level to another programming language at the same level. Example conversion of Java program into C++
In Java , the Just In Time Code generator converts the bytecode into the native machine code which are at the same programming levels.
Hence java is both compiled as well as interpreted language.
why is Java slow ?
The two main reasons behind the slowness of Java are
1) Dynamic Linking = Unlike C, linking is done at run-time , every time the program is run in Java.
2) Run-time Interpreter = The conversion of byte code into native machine code is done at run-time in Java which furthers slows down the speed.
However, the latest version of Java have addressed the performance bottlenecks to a great extent.
Video Transcript
To understand the compiling process in Java ,lets first take a quick look at the linking process in C
Suppose in the main , you have called two functions f1& f2
The main function is stored in file a1.c,function f1 is stored in file a2.c,function f2 is stored in file a3.c
All these files are fed to the compiler , whose output is the corresponding object files, which is the machine code
The linker will club these 3 files together and ,produce a exe file .During program run a loader program will load a.exe into the RAM for execution
Lets look at the same process for java
In your main, you have called two methods f1 & f2.
main method is stored in file a1.java , f1 is stored in file a2.java ,f2 is stored in file a3.java
The compiler will compile the three files , and produce corresponding .class files which consists of the bytecode , unlike C , No linking is done
The JVM (Java Virtual Machine) resides on the RAM
During execution ,using class loader the class files are brought on the RAM. The bytecode is verified for any for any security breaches using the byte code verifies of the JVM, Next the execution engine will convert the bytecode into native machine code.
This is just in time compiling
It is one of the main reasons why Java is comparatively slow
There is more to the JVM architecture which will be discussed in later tutorials