• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What about linux then ?

 
vaibhav panghal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we say that the compiler of java for all operating systems is the same and that only jvm differs from OS to OS . pick a bytecode from windows and execute it on linux - easy . but i had this trivial question in mind . is the compiler of java 'exactly' same for linux and windows ? i mean to say that the windows java compiler is called javac.exe , right ? but .exe don't run on linux . so maybe there is some catch involved . what say ?
 
Seamus Minogue
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well the executable programs like the compiler or javadoc would differ from platform to platform.

What is important is that the byte code compiled on windows will run the same (ish?) under a JVM on linux, Unix, Solaris, whatever as it would under windows. And vice versus.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vaibhav panghal:
we say that the compiler of java for all operating systems is the same and that only jvm differs from OS to OS


I don't think this is correct. The java.exe you run on Windows is not exactly the same file as the java program you run on Linux.

The important thing is that the generated bytecode will run on any valid JVM.

For years I would develop code on Windows, and simply copy the bytecode (.class file) to Unix systems and it ran.

There are differences, especially if you use JNI. But in general, its write once, run everywhere.
 
vaibhav panghal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i know that the bytecode remains the same for every platform . but don't they say that there is just one compiler for all OSs.....that we don't write separate compiler for each OS ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vaibhav panghal:
but don't they say that there is just one compiler for all OSs
Who is "they"?
 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler must be native for the platform on which you compile.

The JVM must be native for the machine on which you execute.

The bytecode generated by a compiler on any platform should be capable of executing on a JVM on any platform.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way: note that "javac.exe" is just a little wrapper application that fires up a JVM and invokes the Sun Java compiler, which is written in Java. So in fact, they do ship the same compiler for every platform; it's just the little launcher app that must be platform-specific.
 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not know that Ernest and it is indeed interesting. Thanks.
 
vaibhav panghal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh thank you so much Ernest . i was also thinking on the same lines - the compiler code remains the same , its just the change in application that invokes the compiler ( which is needed to be platform specific ) . thank you again . javaranch is a great place to be in .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic