what is the difference between compiler and interpreter.when compiler is present in the java then what is the function of interpreter in java
A compiler takes all of the code you wrote and then runs it threw the compiler and then generates a file (i.e.: "myprogam.exe") which is basically a lot of assembly code. An interpreter does not go threw this process of compiling and you can change things much faster and see the result much faster. However compiled code is much faster because you cant just open the source file, change, save and it works.
A compiler takes your source code written in some high-level language and turns it in to machine code. For C/C++ this is machine code for the specific microprocessor you're going to run the executable on. The compiler knows the architecture of the processor (registers, memory model, etc) and the instructions available within the processor, and can turn your high-level code into low-level instructions. If you want to run your compiled code on a new machine you have to find a compiler that can compile your code for that new machine. An interpreter takes your source code an "interprets" it immediately. It does not convert it to another form. An interpreter has its own environment in which it maintains your variables, and loads your code and libraries, etc. When it interprets a line of code it makes modifications to this environment. The interpreter has to run on a computer, though, so IT has to be compiled to machine code. But if you want to run your interpreted code on another machine, you have to find an interpreter that can run on that machine. Java is a hybrid of these two concepts. It has its own "virtual" machine, so it acts like an interpreter. But you compile your java code to "bytecode" so java is a compiled language. The java virtual machine (JVM) is interpreting this bytecode. Third party developers write interpreters and compilers. YOU write your code. If you write a python program, then you can run it on any computer with a python interpreter. If you write a java program, then you can compile it on any computer with a java compiler, then run it on any computer with a java interpreter. If you write a C++ program, then you can compile it on any computer with a C++ compiler, then run it only on that computer.
Join our real-time social learning platform and learn together with your friends!