Use JDK , I can compile a .java file into a .class file, then I can run the .class file, does this mean that the .class file is the final executable file running on JVM ?
Moreover, what's a jar file ? and the difference between jar file and .class file ?
-
possible duplicate of Difference between java class and jarGreg Hewgill– Greg Hewgill2012-08-11 10:15:13 +00:00Commented Aug 11, 2012 at 10:15
2 Answers
1. A class file is a byte code files, which is executed by the JVM, it has no meaning outside the JVM. Making it meaningful only on JVM but not outside, is what makes every java program run in its own sandbox .
2. Jar file is a collection of all the class file, libraries necessary to run the program, consider its an easy way to pack all the files and depending library and providing a single file. We also have Runnable Jars which can be known as Executable Jar
////////// EDITED PART//////////////////
Now this byte-code is converted to machine level executable during Run-time by the JIT (Just In Time Compiler). JIT will look for the runtime intensive part of the program during Runtime, and then it will convert it into machine level executable, this part of the program is known as Hot-spot, and the JIT is known as Hot-Spot-Compiler.
11 Comments
A jar (java archive) as its name says is an archive or collection of java classes that are ready to be executed.
A java decompiler is a tool that makes a reverse engineering from .class extension to .java extension.
To make a jar use following link
http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
Or using windows command promt
jar cf JAR_FILE_NAME FILE_NAMES_OR_DIRECTORY_NAME
e.g.
jar cf MyApp1.jar C:\JavaProject\MyApp