aspose file tools*
The moose likes Beginning Java and the fly likes What about linux then ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What about linux then ?" Watch "What about linux then ?" New topic
Author

What about linux then ?

vaibhav panghal
Greenhorn

Joined: Feb 24, 2008
Posts: 25
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

Joined: Jun 24, 2008
Posts: 41
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

Joined: Aug 11, 2007
Posts: 4655
    
    5

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

Joined: Feb 24, 2008
Posts: 25
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

Joined: Jan 10, 2002
Posts: 61206
    
  66

Originally posted by vaibhav panghal:
but don't they say that there is just one compiler for all OSs
Who is "they"?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
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.


------------------------
Bob
SCJP - 86% - June 11, 2009
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
I did not know that Ernest and it is indeed interesting. Thanks.
vaibhav panghal
Greenhorn

Joined: Feb 24, 2008
Posts: 25
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 .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What about linux then ?