• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

compilation & interpretation

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q. What is actually happening behind the scene when we compile the .java file & when we interpret the .class file ? can any one pls give me a full step wise summery of what is going on behind the scene's during these two processes.
 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Amit,

In java running & executing a program is two step process. The first step is compilation & then it is interpretation.

After we write a program (source code with ext filename.java) , we write javac <filename.java>. This step is the compilation part. The compilation basically checks for language errors or syntax errors. There are certain rules that java follows, for ex, each statement should end with semicolon, the syntax of for loop etc. When a program is successfully compiled, the compiler says something like ... okay this source code is according to the java rules. When a program is compiled, it creates a .class file or more precisely byte code

The second part is the interpretation part. Now this bytecode is executable by any machine that has a JRE or JVM. The byte code, is a code that is independent of all the systems. So any device/pc capable of executing java can execute the above byte code. The JVM is basically the virtual machine within an physical machine. The JVM basically interprets the byte code / class file to execute the program.

The above two parts is quite a power ful due to the fact that the above process makes java platform independent. It is due to the fact that the java code is execuited by the virtual machine rather than the phycial machine.

I am not sure whether how successful i was in solving your query...
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nicely put.

"Platform independent" is a bit vague and misleading. It's Sun's term so blame them. I'd rather say byte code is portable to any compatible JVM. So you can compile source to byte code once and run that byte code on any platform that has a JVM. The byte code might do things that don't work on that platform, like trying to exec() Internet Explorer on UNIX, but that's the programmer's fault, not Java's.

There is one more step just to make things confusing. Some or most JVMs have "hot spot" technology to compile the byte code again, this time creating machine code for the hardware and OS where it is running. After a little overhead for compiling this machine code can run significantly faster than the byte code interpreter.
 
reply
    Bookmark Topic Watch Topic
  • New Topic