• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Ranch Hand
Posts: 114
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guys,
I could not understand Why is the compiler platform independent while JVM is platform dependent?
Please could anybody explain it??
Thanks
 
Sheriff
Posts: 9692
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JVM converts the instructions in the byte code (generated by the compiler) into machine level instructions (sort of) so it needs to know the OS. The JVM makes your code platform independent but there is not another layer between the JVM and the OS to make the JVM platform independent. The JVM has to interact with the OS but the compiler has to generate instructions for the JVM which are the same for all OS...
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compiler is not platform independent. Each platforms needs its own compiler. The bytecode produced by the compiler is what is platform independent.
 
Aashu Mahajan
Ranch Hand
Posts: 114
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:The JVM converts the instructions in the byte code (generated by the compiler) into machine level instructions (sort of) so it needs to know the OS.



suppose If a java application developed on any platform and compiled it, the JVM makes the byte code from the compiled program and for that it communicates with the OS on which the code compliled and when that byte code is ported to different platform or different OS so their JVM (on which the byteCode is ported) again communicated with the byteCode to run it, is it???
Please remove my confusion.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The compiler is not platform independent.


I'm not so sure about that. javac, for example, consists largely of Java classes that I'm fairly certain are the exact same ones on all platforms. javac.exe is a native starter app, but I don't think that does much in the way of compiling. The most platform-specific thing the compiler does would seem to be reading and writing files from/to the file system.
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic