There are three ways to distribute and run Java programs.
Java Applications
Java Web Start
Java Applets
Each distribution method is slightly different and has its advantages and disadvantages. Although developers or curriculum authors will usually adopt a single distribution mechanism, the web pages in this section show you how Open Source Physics programs can be distributed using any of these methods.
Java programs require that a Java Virtual Machine (VM) be installed on the client computer's operating system. Virtual machines are available from various commercial vendors and from open source websites. Apple and Sun Microsystems, for example, include a Java VM with their operating systems whereas Microsoft does not. A Java VM for Microsoft Windows is, however, available free of charge from the Sun Microsystems website.
When installing Java, users should consider installing a complete Java development kit (JDK) rather than just the Java runtime (jre). The Java runtime contains only the VM that allows users to run Java programs whereas the complete JDK (60 Meg) allows users to develop and package Java programs. (The JDK includes the Java runtime.) Various Open Source Physics applications (such as the Ejs modeling tool) make use of programs within the JDK and can therefore only be run if the JDK is installed. The most difficult part of installing the JDK is deciphering the Byzantine nomenclature. Installing the JDK is usually no more difficult than double-clicking on a downloaded file. The Help and FAQ section of this website describes this process for various operating systems.
Java programs can be run and distributed as browser-based applets, stand-alone applications, Java Web Start applications. Because each of these distribution mechanisms has strengths and weaknesses, we have developed a framework that that supports all three mechanisms.
Java programs are almost always packaged in java archive (jar) file such as osp_demo.jar of osp_guide.jar. These jar files contain compiled code, resources such a images and data files, and a manifest containing startup instructions. Double clicking on a jar file executes the program whose name is specified in the manifest.
Although you can run a jar file using only the Java VM, you need the Java software development kit (JDK) to create a jar file. The OSP website contains numerous ready to use jar files that can be run as Java applications or as applets.
A Java application is a program that runs just like any other installed program. Running an OSP program as a Java application is the simplest most reliable way to run the program because the program has complete access to local resources using file (security) permissions that are set by you or your local system administrator.
The jar file containing the Java program is downloaded and placed in a directory on a local computer. Users should then be able to double-click on the jar file to execute the main program within the jar provided that Java is installed on the local computer and that the file system browser associates the "jar" extension with the Java Virtual Machine (VM).
Users may also execute a jar file from within a console (terminal) although it is unlikely that students will want to deal with the complexities of command-line syntax. For example, the osp_demo.jar file can be executed by entering:
java -jar osp_demo.jar
Although a jar file can contain many Java programs, only one program can be designated as the jar file's main program. This main program is specified in a text file within the jar known as a manifest. There are ways to override the manifest and thereby execute other programs within a jar but a more convenient approach is to use the Launcher program. Launcher is a Java program that is designed to execute (launch) other Java programs. We use Launcher to organize and distribute collections of ready-to-use programs, documentation, and curricular material in a single easily modifiable package. (See the Launcher and LaunchBuilder descriptions in this section.)
A Java Applet is a program that is embedded into an html page and run within a browser. Because browsers access the Internet, applets have restricted access to a local computer's resources. In addition, support for applets and advanced features such as the Java to JavaScript communication (live connect), may vary from browser to browser. Nevertheless, applet support is sufficiently widespread and robust that we have developed an Application Applet that allows us to run a Java application as an applet without changing any code. (See examples in the Application Applet description in this section.)
Java Web Start combines the features of Java applications and applets. A Java Web Start application is distributed via the Internet but is installed on a user's desktop and runs as an application. Because a Java Web Start Application has access to local resources, the jar file containing the program must be signed by the developer. Signing a jar file adds security information to the jar file and insures that it has not been tampered with. Note that a user must trust the program developer and explicitly give permission for the program to install itself on the client computer before the program can run. (See examples in the Java Web Start description in this section.)