aspose file tools*
The moose likes Beginning Java and the fly likes compilation in JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compilation in JAVA" Watch "compilation in JAVA" New topic
Author

compilation in JAVA

gauravkv gupta
Greenhorn

Joined: Feb 18, 2012
Posts: 21
Hi all,

I need to know how compilation is done in JAVA. Is it done by JVM.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

gauravkv gupta wrote:Hi all,

I need to know how compilation is done in JAVA. Is it done by JVM.


That's a very broad question. For that kind of question, you should SearchFirst(⇐click) and only post to a forum once you've done some research and have a more specific quesitons.

A couple of things to note though:

1) It's Java, not JAVA. It's not an acronym.

2) You'll need to be specific about what kind of compilation you're asking about. When people talking about compiling in a Java context, they usually mean compiling Java source code into byte code, which is done by a compiler, not by the JVM. However, another possible meaning for your question is about the JVM compiling byte code to native code during execution. For that you could start your research by reading up on "java hotspot".
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

Partly. First a compiler like javac.exe will compile Java to bytecode, stored in .class files. Then when you run a class, the JVM may compile parts of it to native code when it feels it's a good thing to do so, or it may just interpret the bytecode and run it immediately.

For a more detailed and technical description you could take a look at the Java Virtual Machine Specification. It's no easy reading though.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Stephan van Hulst wrote:
For a more detailed and technical description you could take a look at the Java Virtual Machine Specification. It's no easy reading though.


That will cover compiling to bytecode. I don't think it covers anything about compiling bytecode to native, since that's purely up to the implementation.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

gauravkv gupta wrote:I need to know how compilation is done in JAVA. Is it done by JVM.

Short off, Yes. compiler is made by logic/thinking ... compiler is a software
gauravkv gupta
Greenhorn

Joined: Feb 18, 2012
Posts: 21
Stephan van Hulst wrote:Partly. First a compiler like javac.exe will compile Java to bytecode, stored in .class files. Then when you run a class, the JVM may compile parts of it to native code when it feels it's a good thing to do so, or it may just interpret the bytecode and run it immediately.

For a more detailed and technical description you could take a look at the Java Virtual Machine Specification. It's no easy reading though.


Since JVM is a virtual machine then my question is how is it possible to compile to native code using a Virtual machine. Unit which compile the byte code is JVM or JRE.
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

First install jdk from oracle website


First you need to set the path variable in command prompt


Compile the file


run the file



http://www.lifesbizzare.blogspot.com || OCJP:81%
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
gauravkv gupta wrote:Unit which compile the byte code is JVM or JRE.

Java Runtime Environment (JRE) just gives you a execution environment for executing your byte code. JRE itself contains a native JVM implementation and other required jars / libs to execute your java program (byte code).

The tool that compiles your java classes into executable byte code is compiler (javac tool that comes with JDK).

Wiki - JVM
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

gauravkv gupta wrote:
Since JVM is a virtual machine then my question is how is it possible to compile to native code using a Virtual machine.


It's a piece of software. Software can do whatever we tell it to do. The JVM compiling byte code to native code is no different than a C compiler producing native code.

Unit which compile the byte code is JVM or JRE.

As I said in my first reply: The compiler (usually javac) compiles source code to byte code, and the JVM can compile byte code to native code.

The JVM is part of the JRE.
 
jQuery in Action, 2nd edition
 
subject: compilation in JAVA