• 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

What is Java Interpreter or Compiler?

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exaclty is java is it an interpreter or compiler? I have been told by my colleague that there are two phases to executing a program. compiling a source code java file to class file and the the jvm transforms the class file to byte code can anyone tell me the process of executing a file.
Thanks in advance
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chandra
The entire process would be something like this:
you write your code and save it as a .java file.
The compiler takes your .java file and compiles it into a .class file (the .class file contains Java byte code).
The interpreter comes in when your program is run. The JVM (or interpreter) takes your .class file and interprets it. Keep in mind that more and more frequently as JIT becomes more prevalent it is code is not just interpreted anymore it is actually compiled at run time into native machine code. Each platform has a JVM written specifically for it so thatt he JVM for say a Macintosh knows exactly how to interpret the byte codes produced by the compiler (the .class file) and make them work on a mac, same for a Windows JVM.
Hope that that helps.
[ October 13, 2003: Message edited by: Dave Vick ]
 
Chandra Bairi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dave,
I'll just explain kindly let me know if that is correct.
1)Firstly we write a java file with .java extension.
2)That is compiled to .class file which contains Java byte code.
3)This .class file is interpreted by JVM i.e it interprets the byte code to native OS code.
4) The code is executed while interpreting by the JVM.
When asked about java what should I exaclty say is it a compiler or interpreter
Kindly correct me at any step and please dont mind i have no idea about JIT.
Thanks a lot .
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
First , Java is Object Oriented programming language. Java is the language itself . The compiler is the tool that used for create a byte code file (.class), the the Java Virual Machine can understand, according to a text based file(.java) written in Java code. JVM is where the Java byte code file(.class) can be run .
Second, JIT is one of the java compilers (Just-In-Time compiler).
Third,
"This .class file is interpreted by JVM i.e it interprets the byte code to native OS code."
This is not accurate . The .class file is interpreted by JVM that means JVM reads the .class file and understand it.So when u run a java program it understands what to do.
Last, I hope that I was helpful for u and sorry if it was not clear.
Thanx
Ala'a
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chandra
You have pretty much got the idea, but I get the feeling the concept of the JVM interpreting the byte code (.class files) is still not completely clear to you. The reason that you need to use a JVM (Java Virtual Machine) that is appropriate to your platform (there is one for Windows, one for Linux, one for OS X, etc.) is that the JVM is acting as the middleman between the byte code and platform-specific OS calls. So, for example, when you have a line of Java code that looks like:

the JVM (interpreter) knows what needs to be done in say, a Windows environment, to make sure that the intent of the instruction is honoured (in this case that means talking to the OS and asking it to print the "Hello World!" text to the console). 'What needs to be done' for Linux is different to what needs to be done on Windows. It is therefore the JVM that is Java's interpreter.
Don't worry too much about JIT compilation for now, this might confuse you (it is not the same as source code compilation, rather it is something that happens whilst a Java program is running [being interpreted], in an attempt to make it run more efficiently). It is something the JVM does for you.
So, if somebody asks you whether Java is a compiled language or an interpreted language, the answer is that it is in fact both. Perhaps it would be useful for you to read a quick explanation of what a traditional interpreted language is, what most people understand by a compiled language, and how Java fits into these definitions:
Compiled Vs Interpreted
Examples of interpreted languages: JavaScript, Perl, Python
Examples of compiled languages: C, C++
Hope this helps
Michael
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chandra
You've pretty much got it. Like Alaa said though the JVM does not neccesarily turn the byte code into native code unless it uses a Just-In-Time (JIT) compiler. And even then it might only be a small part of the code that gets compiled to native code.
Basically the interpreters job is to read the Java byte code, then decide how to make the operating system do what it is that the byte code says.
When asked which is the interpreter and which is the compiler, the simplest answer is that the compiler takes the .java text file and turns it into java byte code in a .class file. The interpreter, or JVM, is what reads the byte code, the .class file, and causes it to execute.
Hope that helps
 
Ranch Hand
Posts: 216
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still helpful, even after 10 years .......
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Slight change: you can assume nowadays that JVMs are JIT until proven otherwise. They run much faster than they used to.
 
Nikhil Sagar
Ranch Hand
Posts: 216
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sherrif, i have a doubt, in below link

http://docs.oracle.com/cd/E15289_01/doc.40/e15058/underst_jit.htm

this example says that jit changes method call to returned values.

But what if method does not return anything ??
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In which case it would not inline anything.
 
Nikhil Sagar
Ranch Hand
Posts: 216
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:In which case it would not inline anything.



Ah, means JIT comes into play if and only if method returns somthing .
am i correct Sherrif ??
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. It means it cannot inline the return value from a method which hasn’t got a return value.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nikhil Sagar wrote:Ah, means JIT comes into play if and only if method returns somthing .
am i correct Sherrif ??


Given that you've revived a 10-year-old thread, maybe the more relevant question is: Why do you want to know this?

Winston
 
Nikhil Sagar
Ranch Hand
Posts: 216
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Nikhil Sagar wrote:Ah, means JIT comes into play if and only if method returns somthing .
am i correct Sherrif ??


Given that you've revived a 10-year-old thread, maybe the more relevant question is: Why do you want to know this?

Winston



Just for knowledge.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic