Is it possible to execute a JAR file on any OS (like Windows, Linux, Mac OS X)? I want to build a simple application that I want to run on Linux, Windows, and Mac OS X. Could the JAR file be run on any OS with java installed?
Yes, as long as you don't use any native libraries (JNI) this is how java works. It's platform independent.
Jar files are designed to run on any OS that has a JVM of a compatible version installed. Some jar files, however, may have be compiled from Java code that used OS-specific code (say talking to Windows registries), so testing it on other OS's is wise.
As other said, as long as you have Java installed and avoid using native code, you should be good to go. One thing to note is that you can usually run a JAR file just by double clicking it, and it opens like a native executable (on Windows this is how it works by default, on other OSes you can configure this behavior).
Such JAR files are called executable JAR files. If what you want to create is an executable JAR file, then you need to add a manifest file that tells the Java virtual machine (JVM) the name of the main class. Executable JAR files also can be run on the command line by doing:
java -jar myprogram.jar
If your JAR is not an executable JAR, then to run your program you have to add the JAR to your classpath and then execute the main class. To add a JAR to the classpath:
java -classpath path/to/your/program.jar com.mypackage.Main