Explain the purpose of jar file. Can you explain how to create a jar file in java.
A Jar file contains mostly .class files and optionally other files like sound files, image files for Java applications, gathered into a single file in the compressed format. The JDK consists of all java class libraries are available as jar files. In an enterprise a Java application can be started with a Jar file.
A jar file can be created from the command line / console window by using the ‘jar’ command.Example:
jar –cvf inventory.jar *.class
In the above example, all the .class files are compressed and stored in the jar file ‘inventory.jar’. Now, the inventory.jar is a class library for inventory operations of an enterprise. The ‘c’ stands for create, ‘v’ stands for verbose, means to show details while creating the file and ‘f’ stands for the file followed by it.