• 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 in JAVA

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I need to know how compilation is done in JAVA. Is it done by JVM.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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".
 
Saloon Keeper
Posts: 15524
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First install jdk from oracle website


First you need to set the path variable in command prompt


Compile the file


run the file

 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic