Zeek_62_63_Compiler_VS_Interpreter_and_Java platform independent or not


WHAT DOES COMPILER OR INTERPRETER DO ?

We generally write a computer program using a high-level language

A high-level language is one that is understandable by us, humans. This is called source code.

NOTE--> However, a computer does not understand high-level language. 

Computer only understands the program written in 0's and 1's in binary, called the machine code.

To convert source code into machine code, we use either a compiler or an interpreter. 


IN SHORT

SOURCE  CODE            |------------------------------------------------->  |         MACHINE CODE

(High Level Language)  |------------------------------------------------->  |    (Low level Language)   

(For HUMANS)             |------------------------------------------------->  |       (For Computer)

                                                Job of Compiler or Interpreter 


                               Interpreter Vs Compiler

Interpreter Compiler
Translates program one statement at a time.Scans the entire program and translates it as a whole into machine code.
Interpreters usually take less amount of time to analyze the source code. However, the overall execution time is comparatively slower than compilers.Compilers usually take a large amount of time to analyze the source code. However, the overall execution time is comparatively faster than interpreters.
No Object Code is generated, hence are memory efficient.Generates Object Code which further requires linking, hence requires more memory.
Programming languages like JavaScript, Python, Ruby use interpreters.Programming languages like C, C++, Java use compilers.


Working of Compiler and Interpreter

Working of Compiler and Interpreter
IS JAVA  INTERPRETED  OR  COMPILED?
 Java is both Interpreted and compiled.
JAVA is platform independent.                                                                                                 Java is completely portable; the same Java code will run identically on different platforms, regardless of hardware compatibility or operating systems.
           Step by Step execution of the Java program:
  1. Write Java code and save the file with .java
  2. Now, this file will be compiled using the Java compiler, which is javac.
  3. The Java Compiler will compile the Java file and create a .class file having byte code .
  4. This generated byte code is a non-executable code, and now it needs an interpreter to convert it into machine code. Here the JVM handles it.
  5. Now, JVM will execute this byte code to execute Java byte code on a machine.
  6. Now, our program will perform the functionality and gives the desired output.
      
                              Step by Step execution of the Java program:



                                                   JAVA SOURCE CODE (.java)
                                                                      |
                                                                      |
                                                      JAVA COMPILER (called   javac)
                                                                        |
                                                                        |
                                                         JAVA BYTE CODE (.class)
                                                         /                            \
                                                       /                                \
                                                     /                                    \
                           JAVA INTERPRETER                          BYTECODE COMPILER
                                                     \                                      |
                                                      \                                     |
                                                         --------------------     MACHINE CODE




Comments

Popular posts from this blog

Zeek_31_MethodInJava.java