An interpreter is a software program that converts code from high level language to machine format.
No. That's a compiler. An interpreter is a computer program that executes the instructions written in a language. See wikipedia. This is different from a compiler that converts a higher level language into a lower language. The C compiler goes from C to assembly code with the assembler (another type of compiler) translates from assembly to machine code. In Java, the java compiler does code verification and converts from source to bytecode.
now platform for a java interpreter is the JVM, in which it runs, so basically it is going to produce code which can be run by JVM.
The JVM operates on the bytecode directly. The java interpreter is integrated so closely with the JVM that they shouldn't really be thought of as separate entities. What also is happening is a crap-ton of optimization where bytecode is basically optimized (think cc -O3) and inlined on the fly. This makes calling it just an interpreter seem inadequate.
so it takes the bytecode produces intermediate code and the target machine code and gives it to JVM.
JVM in turns executes that code on the OS platform in which JVM is implemented or being run.
I'd rather say that the JVM uses the bytecode, optimized user code, the java libraries which include java and native code, in conjunction with OS calls to execute java applications.
now i am still not clear with the sub process that happens in between i.e. 1. interpreter produces intermediate code. 2. interpreted code is then optimized. 3. then target code is generated 4. and finally executed.
No. The Java compiler generates bytecode. When the JVM executes the code, steps 2-4 happen at runtime inside of the JVM. It is very different than C (for example) which has these separate steps being run by different utilities. Don't think about this as "subprocesses".
Yes although at some point the OS and the CPU come into effect.
and does executing means it gets executed in JVM or in the underlying OS ?
Uh, it gets executed by/in the JVM which is running as a process inside of an OS with the CPU and the rest of the hardware architecture responsible for executing the machine code.
thanks for such a nice explanation, still this topic is very vast and pretty confusing, i am taking my time to get it. Also in case of c its the assembly language which then translated to machine code by assembler compiler, so in case of JAVA, the bytecode can be taken as (just for example) equivalent to assembly code which then translated to machine code by java interpreter and then executed.
A C compiler is a compiler ... not an interpreter. It may compile to assembly code that this then translated to native code. Alternatively, it may compile directly to machine code.
You keep on trying to use words from the C realm to describe what's happening with Java and the JVM and they really don't apply or are vastly different so any comparison is comfusing @RajanChauhan. See my and Stephen's answer for more details.