javamacoscross-platform

Is the Java compiler the same that is on Linux/Windows?


I wrote some Java code in Ubuntu, but now I need program to run in Mac (it's not supposed to be ready product, I just want to be able to compile the source code). I just wonder, is there going to be a lot to change in code when compiling in Mac?


Solution

  • One of the central ideas of Java is write once, run anywhere - in other words, you only have to write and compile the code once, and then it will run on any platform that has a JVM installed (with the correct version). So, you do not need to recompile your code at all for the Mac or for any other operating system.

    Java compiles to bytecode instead of native machine code. The Java virtual machine interprets and executes that bytecode, and translates it to native machine code using a just-in-time compiler to make it run fast.

    It doesn't matter that your program uses Swing - that by itself doesn't mean that it wouldn't work on a Mac.

    The only reason why it wouldn't work is if you've used hard-coded operating system specific things in your code, like hardcoding Windows paths such as C:\Program Files etc. - those things ofcourse don't exist on Mac OS X or other operating systems than Windows.