• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
Straws are for suckers. Now suck on this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic