Why JVM is an Interpreter

Java programming topics
Post Reply
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Why JVM is an Interpreter

Post by Face » Tue Aug 02, 2011 12:26 am

I have read that JVM is an interpreter.

why it is not a compiler?(I think compiler can fast with bytecode in java.Why they wanna interpreter to do it step by step )
what is the use of it? (why the java language makers did not made it as a compiler)

In most language I heard that they got compilers.
can any one give me a little help on this.No need to be much complex :D
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Re: Why JVM is an Interpreter

Post by Rksk » Tue Aug 02, 2011 1:49 am

There is a small help for your question http://en.m.wikipedia.org/wiki/Java_(pr ... _language)

[ Post made via Mobile Device ] Image
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Why JVM is an Interpreter

Post by Neo » Tue Aug 02, 2011 6:06 am

I have read that JVM is an interpreter.

why it is not a compiler?
Technically, Java is not a fully interpreted language. It is called a hybrid language. If I elaborate it further, Java has both the functionality of a compiler and an interpreter.

First Java compiled a Java source code to an intermediate code called bytecode using a the Java compiler commonly known javac. This byte code is the machine code for Java Virtual Machine. So when we run a Java compiled program, what JVM does is, take each instruction from bytecode and execute on the actual machine using interpreting or JIT compiling (Just In-time Compiler). So you must be clear that Java has both the functionality of a compiler (javac) and an interpreter (JVM). However, JIT compiling (not interpreting) is used in most JVMs today to achieve greater speed. There are also ahead-of-time compilers that enable developers to precompile class files into native code for particular platforms.

FYI: You know there are several processing architectures. RISC and CISC are common. There is another architecture called Push-Pop (Or Stack based). Java Virtual Machine is a virtual processor with Push-Pop architecture. At the time of uni, I have decompiled the bytecode for a 4th year assignment. It was fun ;)

FYI: Java developers first planned to release JVM as a chip (additional microprocessor) which will come with every motherboard. Read PicoJava. Obviously it became a failure since no one has agreed to fix that for an additional cost. Note that some ARM processors can execute Java directly. Read Jazelle. I guess this is why Android run only on ARM (as a mobile platform).
I think compiler can fast with bytecode in java.Why they wanna interpreter to do it step by step )
what is the use of it? (why the java language makers did not made it as a compiler)
The point is this. One of the main aims of Java is to make a language which can be run in any platform without recompiling. This is why Java can state it is Platform Independent.

If you use a classic compiler, it compiles the code to machine instructions of the current machine. There is no guarantee that it will get executed on another Operating System. For example: You can't run EXE files directly under Linux. You will have to recompile your code. Java answers this problem. You can run a compiled Java code in any platform with a JVM implementation (I guess almost all major platforms now have a JVM).

So it is clear that though compiled languages are father, those can't be run in other platforms (OSs). I guess I answered your question.
In most language I heard that they got compilers.
can any one give me a little help on this.No need to be much complex :D
Actually most languages you find today are hybrid just as Java.

If you take all the languages in .Net platform, all are hybrid just as Java. .Net framework is the one which acts like JVM. Once the .Net framework is ready on Linux, people will be able to run those .Net compiled codes in Linux without recompiling.
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: Why JVM is an Interpreter

Post by Nipuna » Tue Aug 02, 2011 8:03 am

Neo wrote:
I have read that JVM is an interpreter.

why it is not a compiler?
Technically, Java is not a fully interpreted language. It is called a hybrid language. If I elaborate it further, Java has both the functionality of a compiler and an interpreter.

First Java compiled a Java source code to an intermediate code called bytecode using a the Java compiler commonly known as Java JIT (Just In-time Compiler). This byte code is the machine code for Java Virtual Machine. So when we run a Java compiled program, what JVM does is, take each instruction from bytecode and execute on the actual machine. So you must be clear that Java has both the functionality of a compiler (Java JIT) and an interpreter (JVM).

FYI: You know there are several processing architectures. RISC and CISC are common. There is another architecture called Push-Pop. Java Virtual Machine is a virtual processor with Push-Pop architecture. At the time of uni, I have decompiled the bytecode for a 4th year assignment. It was fun ;)

FYI: Java developers first planned to release JVM as a chip (additional microprocessor) which will come with every motherboard. Read PicoJava. Obviously it became a failure since no one has agreed to fix that for an additional cost. Note that some ARM processors can execute Java directly. Read Jazelle. I guess this is why Android run only on ARM (as a mobile platform).
I think compiler can fast with bytecode in java.Why they wanna interpreter to do it step by step )
what is the use of it? (why the java language makers did not made it as a compiler)
The point is this. One of the main aims of Java is to make a language which can be run in any platform without recompiling. This is why Java can state it is Platform Independent.

If you use a classic compiler, it compiles the code to machine instructions of the current machine. There is no guarantee that it will get executed on another Operating System. For example: You can't run EXE files directly under Linux. You will have to recompile your code. Java answers this problem. You can run a compiled Java code in any platform with a JVM implementation (I guess almost all major platforms now have a JVM).

So it is clear that though compiled languages are father, those can't be run in other platforms (OSs). I guess I answered your question.
In most language I heard that they got compilers.
can any one give me a little help on this.No need to be much complex :D
Actually most languages you find today are hybrid just as Java.

If you take all the languages in .Net platform, all are hybrid just as Java. .Net framework is the one which acts like JVM. Once the .Net framework is ready on Linux, people will be able to run those .Net compiled codes in Linux without recompiling.

:biggrin: :biggrin: :biggrin: :biggrin: :biggrin: :clap: :clap: :clap: :clap: :clap:
If you take all the languages in .Net platform, all are hybrid just as Java. .Net framework is the one which acts like JVM. Once the .Net framework is ready on Linux, people will be able to run those .Net compiled codes in Linux without recompiling.
I think .net is bit hard to use in Linux. One time i searched for the .net framework for Linux I found this http://www.mono-project.com/Main_Page

But according to forums posts i saw about that. It can't run just as in Windows and it's not working well like .net working on Windows.
Post Reply

Return to “Java Programming”