JAR files
JAR files do not have a direct equivalent in C++, but they are analogous to either a library or an executable (Java makes less of a distinction).
Java execution
To recap, the Java compiler converts Java code to class files (one per Java class). A class file is not directly executable, it is actually a very low level interpreted language. The Java Virtual Machine (JVM) is a program which interprets the class files and “runs” the Java program.
As described previously when a Java program is compiled it creates a folder tree containing class files, replicating the structure and names of all the packages in the source code.
As the JVM runs the program, it uses a class loader to find and load the class files. They aren't too difficult to find, if you know the package and class you want, just look for the corresponding file in the corresponding folder.
This works well enough, but the idea of a program which is distributed over hundreds of files spread around a complex folder tree seems a little crazy (although it does actually work). It would clearly be better if we could hold the program in one file, or maybe a few files, and even better if we could use compression to make it smaller and faster to load (class files compress reasonably well).
JAR files
Enter JAR files (Java ARchive). The idea of taking a collection of files, compressing them and combining them into one file is not new – it is what ZIP does. A JAR file is actually a ZIP file.
Open a JAR file in a ZIP program (change the file extension if necessary) and you will see the folder structure, and the class files inside. There is usually also a manifest file containing extra information (such as the entry point of the program).
The class loader which loads classes from the folder version of the program is also smart enoigh to find its way around a ZIP file.
JAR files can also include resources, such as toolbar icons and a splash screen image. There are no built in restrictions on the type of resources you can include – audio, video or anything else, there is no restriction of the type of data you can add to a ZIP file. Java provides built in support for certain resource types, but your program can also access the resource data directly and provide its own support.
