Reputation: 2285
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?
Upvotes: 0
Views: 4063
Reputation: 206996
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.
Upvotes: 4
Reputation: 22415
Java uses the JVM, or Java Virtual Machine to run the code you compile. As long as you're not using any weird OS-specific features in your program (like binding to non-Java libraries or running system commands), your "compiled" Java will likely run on most Java implementations.
There are more than one JVM version and more than one JVM implementation, so you can run into compatibility issues if you don't keep this in mind.
Upvotes: 4
Reputation: 425368
Don't compile anything! Just send them the jars. The local JVM will do the rest. That's how java works.
Disclaimer: If you need 3rd party library jars, you may need to ship them too or create a war file (or similar packaging) that contains the 3rd party jars you need.
Upvotes: 4
Reputation: 38492
the bytecode will be the same after compilation; but if you used classes that aren't available on the Mac, you will have some more work to do.
Upvotes: 3
Reputation: 20820
As long as you have the right vesion of JRE installed your program should run provided that you don't have hard coded dependencies on the machine it is running on (ie. hard coded file paths, etc).
Upvotes: 5