1. How Java works, packages, jar archive files, and deployment
- The simplest, source---compiler---Output->java virtual machine (JVM).
Javac Party.javajava Party
- Separating the source code from the class file, the source code (. java) is stored in the sources directory, and the output (. Class) is generated in the classes directory.
CD myproject/-D. /classes *. JAVACD MyProject/Classesjava MyApp
- The package into the Jar,jar is javaarchive, which is a PKZIP-formatted file that can wrap a set of class files and only need a JAR file for delivery. The executable JAR on behalf of the user does not need to extract the files to be able to run. The program can be executed in case the class file is saved in the JAR. The trick is to create a manifest file with a JAR of information that tells the Java virtual machine which class contains the main () method.
CD myproject/-cvmf manifest.txt apptest.jar *-cvmf manifest.txt Apptest.jar myapp.class
Where the Manifest.txt file is placed in the classes directory, the contents are as follows:
Main-class:myapp
A Java virtual machine can load a class from a JAR and invoke the main () method of that class. In fact, the entire application can be wrapped in a JAR. Once the main () method starts executing, the Java virtual machine does not care where the class comes from, as long as it can be found on the line. One source is all JAR files that classpath the specified location. If you see a jar, the Java virtual machine queries the jar when it needs the class.
Depending on how the operating system is dynamically set, it is possible to simply double-click the JAR to begin execution, as is the case with Windows and Mac OS x. You can do this by clicking the JAR and asking the OS to open with the "Open with ..." type.
2.
Resources:
1. Kathy Sierra/bert Bates. "Head First Java"
Java Learning Notes