• 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

platform-independent

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

Plz clear this.

Why is the compiler platform-independent, while JVM is platform-dependent?

Thanx in advance

Shrawan Bhageria
 
Ranch Hand
Posts: 227
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shrawan,

A Java compiler performs the job of compiling source (*.java) files to bytecode (*.class). This bytecode is further interpreted by JVM to produce output.

To enrich Java with the feature of write once, run anywhere, it is important that the bytecode generated from a particular source file must be exactly similar in every operating system (so that, you can write your code in Linux, compile it and send your class file to your friend who might want to run it on Windows). Thus the job of a compiler is independent of any operating system. It just needs to convert the source code (which is of a defined syntax) to bytecode (this is also in a defined format, independent of the underlying OS).

For JVM, however, the matter is not so simple. Consider two JVMs, one running on Windows and another one running on Linux. Both have been given similar class file (naturally, resulting from same source code). As per JVM specification, both JVMs must produce exact same output on their respective operating systems. A JVM itself is just a program which executes on top of operating system. Thus, it is dependent on the same for almost every task (memory allocation, resource access, input/output etc.). In other words, a JVM has to know how to work with the underlying operating system, leveraging its supporting features/APIs. This is why JVM is always platform-specific.

Regards,

- Aditya
 
Shrawan Bhageria
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Aditya.

Shrawan Bhageria
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic