Java – Is It Truly Cross-Platform?

cross-platformjava

I want to develop a cross platform application.

Is Java cross platform? I mean, can I develop a Java application in Windows and use it in Mac OS X and Linux?

If yes, how?

I find application written in Java, has two setup file one for Windows and other for Mac. This confuses me.

Any illustration or suggestion will be highly appreciated.

Best Answer

Is Java a cross platform?

Java is cross platform in the sense that a compiled Java program runs on all platforms for which there exists a JVM. (This holds for all major operating systems, including Windows, Mac OS and Linux.)

I mean I can develop Java application in windows and use it in mac and Linux?

Yes, this is possible.

This (and the security aspect) is one of the main advantages of running the programs in a virtual machine.

If yes how?

  • Write your application in Java (In .java files)
  • Compile your application using Eclipse or javac (into .class files)
  • (Optionally) Bundle your .class files in an executable (.jar file)

The very same .jar file can be distributed and executed on Windows systems, Mac systems, etc.

I find application written in Java, has two setup file one for windows and other for mac. This confuses me.

This is because some applications rely on platform-specific features. They are then bundled with different platform-specific libraries.

Unless you're developing an application that itself relies on platform-specific features, (such as for instance low-level system calls), you should be able to do just fine with ordinary Java.

Important comment by @Peter Lawrey:

It can be while the application is platform independent, the setup program is not. e.g. IntelliJ has three platform specific installers which are not written in Java, but have a zip which you can just unzip on any platform and it will work.

Related Question