i was discussing this problem with some of my friends , which is a result of a statement made by my teacher she says that java programs are 80% compiled and 20% interpreted. i was confused that if we have already compiled the java source code that what is the use of interpretation who does interpretation of byte code made by jvm diffrenet means it agains generate some other machine code. pls explain. also pls explain , i read this in Complete Reference Java2 byt patrick naughton and Herbert schildts that 'implementation of jvm is different on different machines thats why we don't compile the bytecode rather we interpret it' this line is taken from the above mentioned book on page 11 para 2 under heading "Java's Magic: The ByteCode"
The Java 'compiler' merely translates the Java Program into 'byte-code' which is the 'language' understood by the Java interpreter. There is not a "compile" taking place as you would expect when a C or C++ program is "Compiled" into Machine Language. Execution for these types of files happens at instantiation (execution) where the Java Programs (.class files) are first loaded into memory before it can be interpreted (executed). HTH
Java really tries to get the best of both worlds when it merges compilation with interpretation. You see, compiled languages are very fast to execute as they don't need to be interpreted (which is a compatatively slow process) but they're not very portable as they're compiled specifically for a given platform. Interpreted languages are just the inverse. Java, rather than choosing one or the other, does a bit of both. First of all, when you write your code, you compile it to create byte-code. These byte-codes are later interpreted by the JVM. At that point, the JVM makes the underlying OS do whatever your code says it should do. You see, by compiling the source code into byte-code, the JVM's interpretation process can be enhanced to run faster. That's why Java doesn't run as slow as some fully interpreted languages (many scripting languages are fully interpreted), but it isn't as fast as a fully compiled language, like C++. However, unlike C++, Java is portable across platforms. If you wanted to take a C++ application from one platform to another, you'd have to compile it twice - once for one platform and once for the other. Java, on the other hand, can be compiled just once and then executed by two different JVM's on the two different platforms. I hope that helps, Corey
Heh. Just when you thought it wasn't possible to complicate matters further, here comes another of your friendly bartenders:- The above is an accurate description of Java compilation and the initial approach taken by modern JVMs. But when the JVM finds that you are executing a particular chunk of code very often, it goes one step further by compiling the bytecode to machine code. This machine code is not interpreted but executed directly by the CPU. So you could say that Java is 80% compiled, 20% interpreted, and reserves the option to compile the remaining 20% on an as-needed basis - Peter [ April 08, 2002: Message edited by: Peter den Haan ]
subject: unable to understand that java programs are 80% compiled and 20% interpreted